Typescript: Upgrading to 2.4.1 runs out of memory.

Created on 11 Jul 2017  路  23Comments  路  Source: microsoft/TypeScript

I tried upgrading typescript versions from 2.3.4 to 2.4.1. Now it runs out of memory.

I don't know how to debug running out of memory. Happy to spend time trying things out and reporting back if there's specific tests that would be interesting or helpful.

TypeScript Version: 2.4.1

Node Version: 6.7.0

Code

// A *self-contained* demonstration of the problem follows...

It's a large project, not sure what is causing the problem.

Expected behavior:

1:40:03 PM - Compilation complete. Watching for file changes.

Actual behavior:

<--- Last few GCs --->

   35596 ms: Mark-sweep 1334.8 (1437.1) -> 1334.8 (1437.1) MB, 1631.3 / 0.0 ms [allocation failure] [GC in old space requested].
   37232 ms: Mark-sweep 1334.8 (1437.1) -> 1334.8 (1437.1) MB, 1635.4 / 0.0 ms [allocation failure] [GC in old space requested].
   38886 ms: Mark-sweep 1334.8 (1437.1) -> 1339.3 (1421.1) MB, 1653.6 / 0.0 ms [last resort gc].
   40580 ms: Mark-sweep 1339.3 (1421.1) -> 1343.8 (1421.1) MB, 1693.5 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x151304fcfb51 <JS Object>
    2: inferFromTypes [~/node_modules/typescript/lib/tsc.js:30232] [pc=0x31d630ac975f] (this=0x151304fe6ec1 <JS Global Object>,source=0x34615336f7a1 <a Type with map 0x106d8495dac1>,target=0x2c44e3c24721 <a Type with map 0x106d8495e099>)
    3: inferFromProperties [~/node_modules/typescript/lib/tsc.js:~30292] [pc=0x31d630abaebe] (thi...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::Factory::NumberToString(v8::internal::Handle<v8::internal::Object>, bool) [/usr/local/bin/node]
 6: v8::internal::Runtime_NumberToStringSkipCache(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
 7: 0x31d6302079a7
 8: 0x31d6308b39ba
 9: 0x31d630ac975f
sh: line 1: 68242 Abort trap: 6           tsc --watch
error Command failed with exit code 134.
Bug Fixed

Most helpful comment

With #17984 merged, immview now compiles, although the repro that @mulyoved sent in still crashes. @aj0strow, can you try typescript@next starting tomorrow to see whether your project now compiles?

All 23 comments

I have an app which demonstrates this error also. (node v8.1.2, tsc 2.4.1)

I run into the same issue and switching to 2.4.0 enables me to continue to work.

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Is happening to me as well.

If that might help fixing the problem - I have a public repository that is affected: https://github.com/arturkulig/immview

FWIW, I was able to solve this in my project by changing all genericized callable types to interfaces.

According to HerringtonDarkholme, types are not cached, whereas interfaces are.

TL;DR: typing that caused >= 2.4.1 to OOM:

  type Typename = <T>(arg: Argtype<T>) => void;

fixed for >= 2.4.1:

interface Typename<T> {
  (arg: Argtype<T>): void
}

Here's the diff in context.

Get FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
tried on versions
Version 2.5.0-dev.20170815
Version 2.3.4
Version 2.4.2 (Tried on 2 separate machines, so problem is not machine specific)

Attached shell output from running tsc on those 3 versions
tsc-log.txt

Environment is Windows7, 32GB RAM
Can share code privately

@mulyoved see my post above for a workaround.

@mceachen thanks, does not help my case, don't have such types in my code

@mulyoved If you add --noStrictGenericChecks does tsc still run out of memory? That flag disables some of the checking added in 2.4.1.

@arturkulig a couple of workarounds for immview while I investigate it: --noStrictGenericChecks returns compile time to around a second. I also tried changing most of the type aliases in Types.ts to interfaces, which reduces compile times to around ten seconds.

Overall, the culprit is the added checking we do in 2.4.1, which exposes bugs and architectural weaknesses that were already there. I'll see if I can find anything specific using immview as a test case.

@sandersn --noStrictGenericChecks and tsc still fail on my project

running with node --max-old-space-size=4096 seem to fix the problem for me

I guess my case is different from this issue, not sure why tsc need more memory, not a big project

@mulyoved what about 2.4.0? (If you don't have time, I'll be in contact shortly to see if you can share your code with me privately so I can continue debugging.)

Actually @arturkulig if you change only OpStream<T> to be export interface OpStream<T> extends Stream<T> { instead of export type OpStream<T> = Stream<T> & {, that is sufficient to work around the crash. I'll try to figure out how intersection defeats our caching, whereas interface extension does not.

@sandersn yes fail also with 2.4.0, (I just sent the code in email)

seem my problem was related to https://github.com/paypal/glamorous/issues/288 upgrade to latest version of glamorous solved the problem and I see a reduction of 10x in memory used 30x in the number of symbols

17947 fixes this issue for collections-library-like code like immview. If you want to try the fix early but can't share your code, try checking out that branch.

With #17984 merged, immview now compiles, although the repro that @mulyoved sent in still crashes. @aj0strow, can you try typescript@next starting tomorrow to see whether your project now compiles?

@sandersn FYI typescript@next fixes the issue with my project also

I updated package.json to point to next and ran yarn. It downloaded 2.6.0-dev.20170825. It just breaks now however.

~/node_modules/typescript/lib/tsc.js:9955
                for (var _i = 0, _a = node.jsDocPropertyTags; _i < _a.length; _i++) {
                                                                     ^
TypeError: Cannot read property 'length' of undefined
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9955:70)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bindContainer (~/node_modules/typescript/lib/tsc.js:15157:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16249:21)
    at ~/node_modules/typescript/lib/tsc.js:15861:17
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9952:25)
    at bindJSDocTypedefTag (~/node_modules/typescript/lib/tsc.js:15857:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15286:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at bindJSDocTypedefTagIfAny (~/node_modules/typescript/lib/tsc.js:16272:25)
    at bind (~/node_modules/typescript/lib/tsc.js:16239:17)
    at bindEach (~/node_modules/typescript/lib/tsc.js:15192:21)
    at visitNodes (~/node_modules/typescript/lib/tsc.js:9572:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9739:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9646:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bindContainer (~/node_modules/typescript/lib/tsc.js:15128:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16249:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9702:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at bindCallExpressionFlow (~/node_modules/typescript/lib/tsc.js:15872:17)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15280:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9721:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindBinaryExpressionFlow (~/node_modules/typescript/lib/tsc.js:15798:17)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15268:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9750:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at bindEach (~/node_modules/typescript/lib/tsc.js:15192:21)
    at visitNodes (~/node_modules/typescript/lib/tsc.js:9572:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9739:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9646:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bindContainer (~/node_modules/typescript/lib/tsc.js:15128:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16249:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9702:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at bindCallExpressionFlow (~/node_modules/typescript/lib/tsc.js:15872:17)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15280:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9721:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindBinaryExpressionFlow (~/node_modules/typescript/lib/tsc.js:15798:17)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15268:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9618:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindVariableDeclarationFlow (~/node_modules/typescript/lib/tsc.js:15844:13)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15277:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at bindEach (~/node_modules/typescript/lib/tsc.js:15192:21)
    at visitNodes (~/node_modules/typescript/lib/tsc.js:9572:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9748:24)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
    at bindChildrenWorker (~/node_modules/typescript/lib/tsc.js:15289:21)
    at bindChildren (~/node_modules/typescript/lib/tsc.js:15175:17)
    at bind (~/node_modules/typescript/lib/tsc.js:16246:21)
    at visitNode (~/node_modules/typescript/lib/tsc.js:9567:24)
    at Object.forEachChild (~/node_modules/typescript/lib/tsc.js:9746:21)
    at bindEachChild (~/node_modules/typescript/lib/tsc.js:15200:16)
error Command failed with exit code 1.

@aj0strow this looks like a different issue. can you please file a new one for it, and give us the source file that it triggers the crash.

The crash @mulyoved observed when using glamorous is very likely from glamorous' use of Omit; it is a complex mapped type that implements negatypes.

I've had to revert back to 2.3.2 to get my builds to work. Any idea when this release will be available?

@electricessence 2.5.3 has the fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

dlaberge picture dlaberge  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments