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

Symbol table corruption leads to runaway memory usage #24015

Closed
RyanCavanaugh opened this issue May 10, 2018 · 6 comments · Fixed by #24050
Closed

Symbol table corruption leads to runaway memory usage #24015

RyanCavanaugh opened this issue May 10, 2018 · 6 comments · Fixed by #24050
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@RyanCavanaugh
Copy link
Member

TypeScript Version: 2.8

Search Terms: symbol corrupt

Code

Note: This only repros in VS (verified in an external project but have not verified in an inferred project yet). I have not yet determined why this is the case.

You will need three files

file1.js

blah.prototype = {
    m: "q"
};

file2.d.ts

declare class blah { }

file3.js

/* do editing here */

Make about 70 edits in file3.js without changing file1.js or file2.d.ts

Expected behavior: Stable memory usage

Actual behavior: Eventually, memory usage climbs exponentially

Root cause here is that in this code:

                if ((source.flags | target.flags) & SymbolFlags.JSContainer) {
                    const sourceInitializer = getJSInitializerSymbol(source);
                    const targetInitializer = getJSInitializerSymbol(target);

sourceInitializer and targetInitializer are the same object and we end up copying the same declarations array into itself, pushing more objects into the (supposedly immutable!)
symbol tables from the SourceFiles and doubling the array length the next time around.

You can verify this hypothesis by stopping before the process OOMs, editing file2.d.ts and file1.js - node will quickly GC back down to the baseline memory consumption because we create a fresh symbol table when the file is edited.

I also can't get this to repro via commandline means, so possibly something else fishy is going on.

@sandersn - I applied the bail-out patch we discussed earlier but the problem is that we still grow the array linearly during the top level of each global merging pass (since we're still doing some writing to the original symbol table). This isn't as bad but is still going to cause problems in longer editing sessions.

Playground Link: n/a

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 10, 2018
@RyanCavanaugh
Copy link
Member Author

I will make an LS build tomorrow that logs this state to the ts server log along with symbol locations so we can collect usable repros from the other people that hit this

@RyanCavanaugh
Copy link
Member Author

Both known repros listed at #24050 (comment)

@gs-akhan
Copy link

Hi, The npm says the version is 2.8.3. When will it be updated ?

Thanks

@sandersn
Copy link
Member

@gs-akhan typescript@rc is on 2.9 now and I think the official release of 2.9 is any day now.

Are you hitting this issue? If so, (1) which editor are you using (2) which libraries are you using?

@gs-akhan
Copy link

gs-akhan commented May 30, 2018 via email

@sandersn
Copy link
Member

@gs-akhan This issue only manifests in the editor, and only with projects that contain javascript, and only with projects that introduce globals instead of using modules for everything. If you are upgrading a project from 2.0, it's unlikely that you have javascript because --allowJs was only introduced in 1.8.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants