You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms: large union, performance, indexed access
Code
typeBigUnion={name: '1';children: BigUnion[];}|{name: '2';children: BigUnion[];// 1000 more .......}|{name: '1003';children: BigUnion[];};typeDiscriminateUnion<T,KextendskeyofT,VextendsT[K]>=TextendsRecord<K,V> ? T : never;typeWithName<TextendsBigUnion['name']>=DiscriminateUnion<BigUnion,'name',T>;typeChildrenOf<TextendsBigUnion>=T['children'][number];exportfunctionmakeThing<TextendsBigUnion['name']>(name: T,children: ChildrenOf<WithName<T>>[]=[],){}
Expected behavior:
It compiles reasonably quickly.
Note: This happens even when children is not a recursive reference. In my project children is an array of specific subtypes of BigUnion but it is closed source.
Actual behavior:
It takes over 90s to compile on a 2019 Macbook Pro using node or the playground link.
Ohhh, 86.44% of total time spent in getRegularTypeOfLiteralType? Yeah, that sounds degenerate. Looks like we don't cache that calculation, so we're re-iterating over the massive union every time.
TypeScript Version: 3.9.0-dev.20200328
Search Terms: large union, performance, indexed access
Code
Expected behavior:
It compiles reasonably quickly.
Note: This happens even when
children
is not a recursive reference. In my projectchildren
is an array of specific subtypes ofBigUnion
but it is closed source.Actual behavior:
It takes over 90s to compile on a 2019 Macbook Pro using node or the playground link.
cpuprofile.prof.zip
Playground Link: Playground Link
Related Issues: #29350
The text was updated successfully, but these errors were encountered: