Skip to content

Out of memory error when building with AOT #3651

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
pleerock opened this issue Dec 20, 2016 · 8 comments
Closed

Out of memory error when building with AOT #3651

pleerock opened this issue Dec 20, 2016 · 8 comments

Comments

@pleerock
Copy link

pleerock commented Dec 20, 2016

When I run ng build --prod --aot

it goes fine until 40%, then it becomes slow, and once it gets to 64% it stucks. It stucks for ~10 minutes and throws exception:

 2649/2791 modules 142 active ...de_modules/socket.io-client/lib/on.js                                                                                                                           
<--- Last few GCs --->

  834523 ms: Mark-sweep 1346.7 (1433.1) -> 1346.6 (1435.1) MB, 913.7 / 0.0 ms [allocation failure] [GC in old space requested].
  835570 ms: Mark-sweep 1346.6 (1435.1) -> 1346.5 (1435.1) MB, 1047.1 / 0.0 ms [allocation failure] [GC in old space requested].
  836555 ms: Mark-sweep 1346.5 (1435.1) -> 1347.9 (1402.1) MB, 984.8 / 0.0 ms [last resort gc].
  837489 ms: Mark-sweep 1347.9 (1402.1) -> 1347.9 (1399.1) MB, 933.7 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0x3a414ebcfb51 <JS Object>
    1: applyPluginsBailResult1 [/Users/pleerock/www/project/node_modules/tapable/lib/Tapable.js:~80] [pc=0x38e7e98874d4] (this=0x214e62096241 <a Parser with map 0x5828c3561c1>,name=0x3320359c0b99 <String[27]: evaluate FunctionExpression>,param=0x33c4cc2bf4c9 <a Node with map 0xf06457379f9>)
    2: evaluateExpression [/Users/pleerock/www/project/node_modules/webpack/lib/P...

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::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::HashTable<v8::internal::StringTable, v8::internal::StringTableShape, v8::internal::HashTableKey*>::EnsureCapacity(v8::internal::Handle<v8::internal::StringTable>, int, v8::internal::HashTableKey*, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::HashTableKey*) [/usr/local/bin/node]
 7: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [/usr/local/bin/node]
 8: v8::internal::LookupIterator::LookupIterator(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::LookupIterator::Configuration) [/usr/local/bin/node]
 9: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [/usr/local/bin/node]
10: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
11: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x38e7e52092a7
13: 0x38e7e98874d4
Abort trap: 6

mac OSX El Capitan
angular-cli: 1.0.0-beta.22-1
node: 6.6.0

Looks like there is memory leak somewhere. We have a big project. 1500 typescript files and almost 100k lines of code.

@celliott181
Copy link
Contributor

celliott181 commented Dec 20, 2016

Probably not a leak, just a cap on your node heap. For others also seeking help with this, the issue is known to plague the CLI (#1652, #2974, #3099) when projects grow beyond what many of us consider small-medium sized codebases.

The fix it to set Node's heap size. This is done with node --max_old_space_size=[Space in MB] followed by whatever call you wanted to make, e.g. node --max_old_space_size=2048 ./node_modules/.bin/ng build --prod --aot (Credit to @hansl for that one line.)

@pleerock
Copy link
Author

Don't really think that this process requires so much memory, either there is a memory leak, either there is a room for huge optimizations

@celliott181
Copy link
Contributor

celliott181 commented Dec 20, 2016

I just built my project into a freshly generated dist. My process averaged 500-600MB and peaked at 883.7MB of memory space in use during the optimization and final emission of the bundle with ng build --prod --aot. I don't have a very large project, just three modules and 176KB of source, but the process keeps the entire build in memory.

@thinkingmedia
Copy link

I was able to build PHP projects, Grunt, Gulp, Phing and Bower projects with a machine that had only 1GB of Ram (Ubuntu 14). That machine compiled my Angular 1 projects for the last 2 years without any issues, and all my other projects.

My first Angular 2 with just a few components triggered this out of memory error. Had to upgrade my node to 2GB just to restore nightly builds.

I also ran out of memory doing npm install when it hit a build for a node dependency introduced by Angular 2.

@pleerock
Copy link
Author

btw even with node --max_old_space_size=4048 ./node_modules/.bin/ng build --prod --aot it brings out of memory error on 92%

@filipesilva
Copy link
Contributor

Dupe of #1652 as @gelliott181 mentioned. It's better to keep issue discussion in a single thread.

@poddarkhushbu07
Copy link

Don't really think that this process requires so much memory, either there is a memory leak, either there is a room for huge optimizations

Any suggestion or trick to find the memory leak or where the optimisation is needed?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants