-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance issue on updating Babel monorepo typescript from 4.7.4 to 4.8.2 #50515
Comments
Here is a smaller reproduction repo thanks to @liuxingbaoyu, though the behaviour is somewhat different, in this reproduction |
I'm not an expert, but this sounds to me like what #50329 intends to fix. |
@ehoogeveen-medweb Thanks for the head-up. I tested with |
|
The issue here appears to be the intersection normalization code that was added in #49119. In this particular repro we end up constructing some very expensive unions of intersections due to the strongly typed |
@ehoogeveen-medweb @ahejlsberg Thanks! |
Bug Report
🔎 Search Terms
out of memory
Symbols
Types
4.8 regression
🕗 Version & Regression Information
4.8.0-dev.20220527
and4.8.0-dev.20220528
💻 Code
❗ It is a large repo. But we have narrowed down the suspicious code paths. See the "Context" section.
Checkout https://github.com/JLHwung/babel/tree/ts-4-8-regression
Run
yarn && yarn tsc --extendedDiagnostics --incremental false
🙁 Actual behavior
4.8.0-dev.20220528:
tsc 4.7.4
tsc 4.8 increases memory usage from 1GB to 4GB, thus performance is worsen from 18s to 73s. The increased memory usage fails our CI by OOM error. The "Symbols" and "Types" significantly increased.
🙂 Expected behavior
Memory usage should not be quadrupled.
👓 Context
The issue surfaced when we upgrade from 4.7.4 to 4.8.2: babel/babel#14880
Later @liuxingbaoyu managed to narrow down the root cause:
https://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-traverse/src/path/index.ts#L111-L113
where
Scope
acceptsNodePath<t.Pattern | t.Scopeable>
.t.Pattern | t.Scopeable
is subset oft.Node
, which is a union of 252 AST types. (https://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-types/src/ast-types/generated/index.ts#L50)The
isScope
is defined ashttps://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-traverse/src/path/lib/virtual-types-validator.ts#L72
where
VirtualTypeAliases["Scope"]
resolves tot.Pattern | t.Scopeable
.It seems to me
tsc
spends quite a bit of effort to checknew Scope(this)
is valid behind thethis.isScope
check. We can workaround the issue by castingthis
toNodePath<t.Pattern | t.Scopeable>
:Yet I expect
tsc
infers thatNodePath<T & VirtualTypeAliases["Scope"]>
must subsetNodePath<t.Pattern | t.Scopeable>
and thusnew Scope
is valid without that much efforts.I did a rough bisect and the issue was first introduced in
4.8.0-dev.20220528
. The regression might be introduced in #49119.The text was updated successfully, but these errors were encountered: