Skip to content

Upgrading to 2.4.1 runs out of memory. #17097

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

Closed
aj0strow opened this issue Jul 11, 2017 · 23 comments · Fixed by #17984
Closed

Upgrading to 2.4.1 runs out of memory. #17097

aj0strow opened this issue Jul 11, 2017 · 23 comments · Fixed by #17984
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@aj0strow
Copy link

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.
@amikhalev
Copy link

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

@arturkulig
Copy link

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

@electricessence
Copy link

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

@arturkulig
Copy link

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

@mceachen
Copy link

mceachen commented Jul 20, 2017

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.

koskimas pushed a commit to Vincit/objection.js that referenced this issue Jul 21, 2017
* s/String/string
* s/Object/object
* replaced callable genericized types with interfaces (see microsoft/TypeScript#17097 (comment)
* coallesced some method calls where union types made sense
* replace Function with `() => void`
* tslint fixed a bunch of missing semicolons
@mulyoved
Copy link

mulyoved commented Aug 16, 2017

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

@mceachen
Copy link

@mulyoved see my post above for a workaround.

@mulyoved
Copy link

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

@mhegazy mhegazy added the Bug A bug in TypeScript label Aug 16, 2017
@mhegazy mhegazy added this to the TypeScript 2.5.1 milestone Aug 16, 2017
@sandersn
Copy link
Member

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

@sandersn
Copy link
Member

@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.

@mulyoved
Copy link

@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

@sandersn
Copy link
Member

@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.)

@sandersn
Copy link
Member

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.

@mulyoved
Copy link

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

@mulyoved
Copy link

seem my problem was related to paypal/glamorous#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

@sandersn
Copy link
Member

#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.

@sandersn
Copy link
Member

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?

@amikhalev
Copy link

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

@aj0strow
Copy link
Author

aj0strow commented Aug 25, 2017

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.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 25, 2017

@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.

@sandersn
Copy link
Member

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

@electricessence
Copy link

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

@emmanueltouzery
Copy link

@electricessence 2.5.3 has the fix.

@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
9 participants