Skip to content

Very high memory usage and crash #18226

@Pauan

Description

@Pauan

TypeScript Version: 2.6.0-dev.20170902 (also happens on earlier versions)

I work at AmCharts, we have a fairly large code base written in TypeScript (~29,315 lines of code), but when compiling with tsc it consumes a few gigabytes of RAM and finally we get this error:

<--- Last few GCs --->

[24391:0x2c63610]    70596 ms: Mark-sweep 1401.0 (1535.3) -> 1401.0 (1535.3) MB, 1770.2 / 0.0 ms  allocation failure GC in old space requested
[24391:0x2c63610]    72459 ms: Mark-sweep 1401.0 (1535.3) -> 1401.0 (1505.3) MB, 1862.6 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1863 ms) last resort 
[24391:0x2c63610]    74312 ms: Mark-sweep 1401.0 (1505.3) -> 1401.0 (1505.3) MB, 1852.1 / 0.0 ms  last resort 


<--- JS stacktrace --->

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

Security context: 0x28731ee29891 <JS Object>
    2: findAncestor [amcharts4dev-0effa4a915dcea363716ff67c2bc2798eeb1d717/node_modules/typescript/lib/tsc.js:~284] [pc=0x38642953cd5f](this=0x24541b5fdfc1 <an Object with map 0x2b2aae5a411>,node=0x272f911b6331 <a Node with map 0x2b2aae4d891>,callback=0x1bd9ab9f80a1 <JS Function (SharedFunctionInfo 0x31ac7bec9ab1)>)
    3: isSymbolInScopeOfMappedTypeParameter(aka isSym...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x13647ec [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::DeoptimizationInputData::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [node]
 7: v8::internal::LCodeGenBase::PopulateDeoptimizationData(v8::internal::Handle<v8::internal::Code>) [node]
 8: v8::internal::LChunk::Codegen() [node]
 9: v8::internal::HCompilationJob::FinalizeJobImpl() [node]
10: v8::internal::CompilationJob::FinalizeJob() [node]
11: 0xd9c4fa [node]
12: 0xd9cd42 [node]
13: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) [node]
14: v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::internal::Isolate*) [node]
15: 0x386428a8437d

This means we don't get any type checking at all, because it crashes with the above error before it finishes compiling. This is seriously hurting our development.

Our code doesn't do anything super crazy with the type system, just a lot of classes and interfaces. However, we do use one particular code pattern which seems to be particularly slow:

interface IFoo {
  foo: number;
}

class Foo {
  _interface: IFoo;

  foo(): this["_interface"] {
    ...
  }
}


interface IBar extends IFoo {
  bar: string;
}

class Bar extends Foo {
  _interface: IBar;
}

It's hard to create a self-contained example because the crash seems to only happen on large projects.

In addition, our code is private. How can I get our code to you so that you can figure out why it's crashing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions