Skip to content

Symbol table corruption leads to runaway memory usage #24015

Closed
@RyanCavanaugh

Description

@RyanCavanaugh

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions