Skip to content
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

Eliminate redundant work in type inference #15863

Merged
merged 2 commits into from
May 16, 2017
Merged

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented May 15, 2017

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.

if (symbol) {
for (let i = 0; i < depth; i++) {
const t = stack[i];
if (getSymbolForInference(t) === symbol) {
Copy link
Contributor

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

@ahejlsberg ahejlsberg merged commit 2a9a6e8 into master May 16, 2017
@ahejlsberg ahejlsberg deleted the fixRedundantTypeInference branch May 16, 2017 16:34
@sledorze
Copy link

will it be part of 2.3.3 ?

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2017

will it be part of 2.3.3 ?

no. this is TS 2.4 bound.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented May 20, 2017

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.

@mhegazy
Copy link
Contributor

mhegazy commented May 20, 2017

Was the other project compiling on 2.3?

@OliverJAsh
Copy link
Contributor

@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

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS v2.3.1 runs out of memory compiling FP library
6 participants