TypeScript: Very high memory usage

I’ve been having issues with the typescript compiler eating up lots of memory.

A run of tsc in my current project reaches around 1.1-1.2GB memory before completion.

This has been causing issues when using awesome-typescript-loader through webpack. It actually crashes after a little while because it exceeds a memory limit (1.5GB i believe) This seems to be caused in part by a memory leak in ATL, but the memory use of tsc on its own is bordering on extreme. I have an issue open on that project as well https://github.com/s-panferov/awesome-typescript-loader/issues/227

I would suspect however, that with a project large enough, tsc could exceed the memory limit on its own.

I can provide an example project if needed.

Node: 6.5.0 TS: 2.0.2

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

By the way I downgraded to 1.8.10 and adding or removing enzyme doesn’t affect so much my building time (around 2seconds in both scenarios).

It’s really with the 2.1.x version that it gets 10 times slower and the memories usage goes to the roof, and it is a shame since I am in love with most of the features in the 2.x branch

I understand. if you look at the enzyme declaration file you will find multiple layers of abstractions using generic types. (It feels too complicated; I do not think I can pass a judgment here though since i am not familial with the framework).

TypeScript has a structural type system. so comparing two entities require the type system to do a full structural comparison. every time two types need to be compared (for inheriting or for checking overloads, or just assignability etc…) the compiler needs to check their structure, that means the source and the target need to have the same set of properties with matching types; if sees a method, it needs to check all its signatures between the source and the target, for every signature, every parameter type as well as return type should be checked; every time there is a reference to a generic type, it needs to be instantiated with the correct generic type arguments; then the whole algorithm is repeated recursively, and so on and so forth. hope that makes sense.

Closing this issue since #11934 resolves the main issue with enzyme typings. #11941 is filed to track solution for the problem in general

@mhegazy appears to be the same with typescript@next

@vladima [removed - use gist from ChrisJamesC below] npm install && typings install then npm start or tsc

npm start uses awesome-typescript-loader as described, it should most likely crash with an out of memory error if you leave it be a while, you may need to do an edit to a file though to cause a re-build… Keep an eye on the memory, it should keep climbing.