-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Eliminate redundant work in type inference #15863
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
src/compiler/checker.ts
Outdated
if (symbol) { | ||
for (let i = 0; i < depth; i++) { | ||
const t = stack[i]; | ||
if (getSymbolForInference(t) === symbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not storing getSymbolForInference(target)
on the stack directly instead of calling it on every entry when we check
will it be part of 2.3.3 ? |
no. this is TS 2.4 bound. |
I'm using Version 2.4.0-dev.20170519 and I've found that the project I shared in #15443 no longer has this issue, however I have a separate project that doesn't compile due to this memory issue. Has anyone else found the same? Will require some work to share a test case. |
Was the other project compiling on 2.3? |
@mhegazy Here is the other project that runs out of memory when compiling on 2.4.0-dev.20170519 and 2.3. https://github.com/OliverJAsh/ts-2.4-memory-issue/compare/2.4.0-dev.20170519 |
With this PR we eliminate redundant work in type inference. Previously, we would explore instantiations of the same generic type up to five levels deep in type inference (which mirrored what we do in relationship checking to detect infinitely recursive types). We now explore just one level as no further inferences will be made beyond that anyway.
This PR doesn't include a regression test as the original issue only reproduces with the fp-ts library. However, I have manually verified that the out of memory issue is fixed and the compile time for the repro is less than 1s. Also, I have verified there are no changes in the real world code suites.
Fixes #15443.