angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Version 9: performance issues & out of memory errors

Open filipesilva opened this issue 6 years ago • 79 comments

If you are experiencing performance problems or out of memory errors with Angular CLI version 9, please let us known on this issue.

filipesilva avatar Feb 07 '20 00:02 filipesilva

ng build -c mhsb

10% building 3/3 modules 0 active
<--- Last few GCs --->

[11664:000001BF4FF4BB60]    82832 ms: Mark-sweep 1372.0 (1455.8) -> 1363.3 (1456.3) MB, 1956.2 / 0.0 ms  (average mu = 0.156, current mu = 0.088) allocation failure scavenge might not succeed      
[11664:000001BF4FF4BB60]    84892 ms: Mark-sweep 1367.8 (1456.3) -> 1365.2 (1456.3) MB, 1955.4 / 0.0 ms  (average mu = 0.105, current mu = 0.051) allocation failure GC in old space requested      


<--- JS stacktrace --->

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

    0: ExitFrame [pc: 000001F0724DC5C1]
    1: StubFrame [pc: 000001F0725040B1]
Security context: 0x0308fb49e6e9 <JSObject>
    2: onSubstituteNode(aka onSubstituteNode) [00000211020875B9] [D:\QLASS\node_modules\typescript\lib\typescript.js:76870] [bytecode=00000000D32B6A19 offset=0](this=0x0323baa826f1 <undefined>,hint=1,node=0x00d01b8a95b9 <IdentifierObject map = 0000034C8ACA3939>)
    3: onSubstituteNode(aka onSubstituteNode) [00000211...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF7B607DD8A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 00007FF7B6058886 node::MakeCallback+4534
 3: 00007FF7B6059200 node_module_register+2032
 4: 00007FF7B63730DE v8::internal::FatalProcessOutOfMemory+846
 5: 00007FF7B637300F v8::internal::FatalProcessOutOfMemory+639
 6: 00007FF7B6559804 v8::internal::Heap::MaxHeapGrowingFactor+9620
 7: 00007FF7B65507E6 v8::internal::ScavengeJob::operator=+24550
 8: 00007FF7B654EE3C v8::internal::ScavengeJob::operator=+17980
 9: 00007FF7B6557B87 v8::internal::Heap::MaxHeapGrowingFactor+2327
10: 00007FF7B6557C06 v8::internal::Heap::MaxHeapGrowingFactor+2454
11: 00007FF7B66872B0 v8::internal::Factory::NewByteArray+112
12: 00007FF7B6AC583C v8::internal::compiler::MachineOperatorReducer::ReduceFloat64RoundDown+7564
13: 00007FF7B6901230 v8::internal::compiler::Pipeline::AllocateRegistersForTesting+4608
14: 00007FF7B68F95DB v8::internal::compiler::ValueNumberingReducer::operator=+10107
15: 00007FF7B653362A v8::internal::Zone::NewExpand+3034
16: 00007FF7B6535C44 v8::internal::Zone::NewExpand+12788
17: 00007FF7B65883B9 v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions+393
18: 00007FF7B642DE23 v8::internal::StackGuard::HandleInterrupts+531
19: 00007FF7B66FEAB7 v8::internal::operator<<+71991
20: 000001F0724DC5C1

alialtun14 avatar Feb 07 '20 10:02 alialtun14

We solve this problem (when compile with ng build -c mhsb) we use following command.

.\ngs.cmd build -c mhsb

ngs.cmd: @node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng %1 %2 %3 %4 %5

When we use this command, when the compile process reaches 92% after 10 minutes, it encounters the error below.

92% chunk asset optimization TerserPluginFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 00007FF7B607DD8A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 00007FF7B6058886 node::MakeCallback+4534
 3: 00007FF7B6059200 node_module_register+2032
 4: 00007FF7B63730DE v8::internal::FatalProcessOutOfMemory+846
 5: 00007FF7B637300F v8::internal::FatalProcessOutOfMemory+639
 6: 00007FF7B6559804 v8::internal::Heap::MaxHeapGrowingFactor+9620
 7: 00007FF7B6557CCB v8::internal::Heap::MaxHeapGrowingFactor+2651
 8: 00007FF7B6681B2B v8::internal::Factory::AllocateRawWithImmortalMap+59  
 9: 00007FF7B66845DD v8::internal::Factory::NewRawTwoByteString+77
10: 00007FF7B6750270 v8::internal::LookupIterator::Start<1>+32464
11: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
12: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
13: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
14: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
15: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
16: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
17: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
18: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
19: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
20: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
21: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
22: 00007FF7B675065F v8::internal::LookupIterator::Start<1>+33471
23: 00007FF7B674FF07 v8::internal::LookupIterator::Start<1>+31591
24: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
25: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
26: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
27: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
28: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
29: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
30: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
31: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
32: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
33: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
34: 00007FF7B674FF3C v8::internal::LookupIterator::Start<1>+31644
35: 00007FF7B674BD62 v8::internal::LookupIterator::Start<1>+14786
36: 00007FF7B674CAD5 v8::internal::LookupIterator::Start<1>+18229
37: 00007FF7B674EE7B v8::internal::LookupIterator::Start<1>+27355
38: 00007FF7B674CB60 v8::internal::LookupIterator::Start<1>+18368
39: 00007FF7B674EE7B v8::internal::LookupIterator::Start<1>+27355
40: 00007FF7B674CB60 v8::internal::LookupIterator::Start<1>+18368
41: 00007FF7B674B77D v8::internal::LookupIterator::Start<1>+13277
42: 00007FF7B63A13FC v8::internal::DeferredHandles::Iterate+1116
43: 00007FF7B6743736 v8::internal::WasmJs::Install+230838
44: 00007FF7B674365B v8::internal::WasmJs::Install+230619
45: 0000014B2DCDC721
# Fatal error in , line 0
# API fatal error handler returned after process out of memory on the background thread
#FailureMessage Object: 000000A352EFA150^CTerminate batch job (Y/N)? y

alialtun14 avatar Feb 07 '20 10:02 alialtun14

@alialtun14 are you seeing this with version 9 now, and did it not happen with version 8?

I'd like to take a look at the project if possible. Giving me access to a new private github repository is a good way of doing this for private projects.

filipesilva avatar Feb 07 '20 11:02 filipesilva

We have taken same error when we used "ng build -c mhsb". We have solved this problen i V8 by using max_old_space_size=8192. Today after upgrading to V9 and compile with max_old_space_size=8192 we started the error again.

alialtun14 avatar Feb 07 '20 11:02 alialtun14

I'd like to take a look at the project if possible. Giving me access to a new private github repository is a good way of doing this for private projects.

Our project is in gitlab reposiyory. If you share your email adrese with [email protected]. I can share zip file of our project.

alialtun14 avatar Feb 07 '20 11:02 alialtun14

Hi - error in private company repo: What could You help:

  • newest cli, and all ng.
  • when targeting es5 all works fine,
  • when target is es2015 , build ends with stackoverflow :/
  • optimalization false helps but this is not a solution :/
WARNING in Terser Plugin: Condition always false [vendor-es2015.89fba3b2bb0ffec12a97.js:181165,4]

WARNING in Terser Plugin: Dropping unreachable code [vendor-es2015.89fba3b2bb0ffec12a97.js:181165,11]

...

WARNING in Terser Plugin: Condition always false [vendor-es2015.89fba3b2bb0ffec12a97.js:39575,8]

WARNING in Terser Plugin: Condition left of || always false [vendor-es2015.89fba3b2bb0ffec12a97.js:61851,19]

WARNING in Terser Plugin: Condition left of || always false [vendor-es2015.89fba3b2bb0ffec12a97.js:61853,23]

WARNING in Terser Plugin: Dropping side-effect-free statement [vendor-es2015.89fba3b2bb0ffec12a97.js:209626,16]

ERROR in main-es2015.d92b662609fbc64cbd74.js from Terser
RangeError: Maximum call stack size exceeded
    at Array.push (<anonymous>)
    at Tn.push (C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:76200)
    at AST_SymbolDefClass.transform (C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:79125)
    at C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:82505
    at AST_ClassExpression.transform (C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:79182)
    at C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:81712
    at AST_Dot.transform (C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:79182)
    at C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:81532
    at AST_Call.transform (C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:79182)
    at C:\source\DEV\MAIN\WebNg8\node_modules\terser\dist\bundle.min.js:1:81712

ps. dont suggest by dir nam - it is ng9 ;)

4zriel avatar Feb 07 '20 13:02 4zriel

@4zriel I edited your comment to remove a large chunk of terser warnings in the log that I reviewed and know is not relevant to the problem at hand. I removed it because it was very long and made it hard to read the rest of this issue thread.

filipesilva avatar Feb 07 '20 14:02 filipesilva

@alialtun14 I just tried building with the increased memory and it seemed to build fine:

kamik@RED-X1C6 MINGW64 /d/sandbox/QLASS.V8
$ node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build -c mhsb

chunk {0} runtime.a8ef3a8272419c2e2c66.js (runtime) 1.45 kB [entry] [rendered]
chunk {1} main.742b09869a13ccbb2f64.js (main) 11.4 MB [initial] [rendered]
chunk {2} polyfills.f5b379c03ee1455b2258.js (polyfills) 45.5 kB [initial] [rendered]
chunk {3} styles.b7204deb7fc86e3c9129.css (styles) 21.5 kB [initial] [rendered]
chunk {4} vendor.8fa60aebff14da44025f.js (vendor) 980 kB [initial] [rendered]
chunk {scripts} scripts.f7e72443ce1ee0185d9e.js (scripts) 229 kB [entry] [rendered]
Date: 2020-02-07T15:13:56.679Z - Hash: fdccd0547616a05c53dd - Time: 905229ms

What version of node are you on? There were a couple of node versions that had memory problems. I am on Node v12.4.0.

@4zriel what version of node are you on as well? Can you try the one I mentioned above, or perhaps considering sharing the project privately with me?

filipesilva avatar Feb 07 '20 15:02 filipesilva

@filipesilva I'll love to share but then I'll propalby need to look for another work ;) I'm using node 13.3.0, and I tried 1st this trick with inceased memory (I set sth about 10k maybe it is too much...) but it didn't change anything...As i said - ng serve and ng buil (without --prod so without --optimization works perfectly fine). It is quite big monorepo, with a lot of iternal lib, but ng update worked surpriselgly well :)

4zriel avatar Feb 07 '20 15:02 4zriel

@4zriel since you have a monorepo, I think you might be suffering from case 2 in https://angular.io/guide/ivy-compatibility#payload-size-debugging. Can you try the approach described in #16799 (comment) and see if it works please?

To be clear, the approach is to add "sideEffects": false to the package.json of shared libraries. If the library doesn't actually have a package.json, you can add one with just {"sideEffects": false}.

filipesilva avatar Feb 07 '20 15:02 filipesilva

@filipesilva That's it! :D You are awasome! I spend like 2h at least on this, read through the docs and other issuess but all I need was just 'sideEffects: false'! :D

4zriel avatar Feb 07 '20 16:02 4zriel

Glad to hear it helped!

filipesilva avatar Feb 07 '20 16:02 filipesilva

@filipesilva

We transferred the project to Angular 9. Thank you for your interest and help.

We can now build with enableIvy: false. When we make Enable Ivy: true and compile, we get errors. We are now in the process of eliminating those errors.

alialtun14 avatar Feb 08 '20 15:02 alialtun14

after fixing errors related to compiling with Ivy

main.js file size : 11.6 MB -> 3.72 MB                
compile time:  1.242.877ms  -> 344.095ms

enableIvy = false

chunk {} runtime.689ba4fd6cadb82c1ac2.js (runtime)       1.45 kB [entry] [rendered]
chunk {1} main.24c2383760bad25975b5.js (main)            11.6 MB [initial] [rendered]
chunk {2} polyfills.390e4275012bfaabf98d.js (polyfills)  44.1 kB [initial] [rendered]
chunk {3} styles.b7204deb7fc86e3c9129.css (styles)       21.7 kB [initial] [rendered]
chunk {4} vendor.036641f6c70e59792222.js (vendor)         971 kB [initial] [rendered]
chunk {scripts} scripts.f7e72443ce1ee0185d9e.js (scripts) 229 kB [entry] [rendered]

Date: 2020-02-08T15:30:59.401Z - Hash: a6f7a979bcf2cf1bc117 - Time: 1.242.877ms

enableIvy = true

chunk {} runtime.689ba4fd6cadb82c1ac2.js (runtime)        1.45 kB [entry]   [rendered]
chunk {1} main.1d16e2ff10cfb77ab889.js (main)             3.72 MB [initial] [rendered]
chunk {2} polyfills.92255d147939824f14c4.js (polyfills)   35.6 kB [initial] [rendered]
chunk {3} styles.b7204deb7fc86e3c9129.css (styles)        21.7 kB [initial] [rendered]
chunk {4} vendor.dbeb455719d37461cc6b.js (vendor)         1.02 MB [initial] [rendered]
chunk {scripts} scripts.f7e72443ce1ee0185d9e.js (scripts)  229 kB [entry]   [rendered]

Date: 2020-02-09T00:31:07.815Z - Hash: 5502a74ac622af53451a - Time: 344.095ms

alialtun14 avatar Feb 09 '20 01:02 alialtun14

@filipesilva

What version of node are you on? There were a couple of node versions that had memory problems. I am on Node v12.4.0.

We started using node v12.15.0 with Angular 9.

After node v12.15.0, we can compile "node node_modules/@angular/cli/bin/ng build -c mhsb" without any memory problems.

Thank you for your interest and help.

alialtun14 avatar Feb 09 '20 01:02 alialtun14

@alialtun14 oh wow that's a great improvement, glad to hear!

filipesilva avatar Feb 09 '20 10:02 filipesilva

Btw @alialtun14 I noticed you have a vendor chunk, we recommend turning it off in production because it causes increases in total size. You can turn it off in your production configuration with "vendorChunk": false.

filipesilva avatar Feb 09 '20 10:02 filipesilva

"vendorChunk": false

PS D:\QLASS> ng build -c mhsb --vendorChunk=false

chunk {} runtime.689ba4fd6cadb82c1ac2.js (runtime)          1.45 kB [entry] [rendered]
chunk {1} main.c44ecad664850cecbc0b.js (main)               4.76 MB [initial] [rendered]
chunk {2} polyfills.92255d147939824f14c4.js (polyfills)     35.6 kB [initial] [rendered]
chunk {3} styles.b7204deb7fc86e3c9129.css (styles)          21.7 kB [initial] [rendered]
chunk {scripts} scripts.f7e72443ce1ee0185d9e.js (scripts)    229 kB [entry] [rendered]
Date: 2020-02-09T10:23:21.399Z - Hash: 86674d0bccda83b7ccf3 - Time: 328.398ms

alialtun14 avatar Feb 09 '20 10:02 alialtun14

@filipesilva According to the blog post by @StephenFluin, bundle size in large app can reduce maximum %40 with ivy compile. In our project we reached to %68 in size and % 72 in time reduction. Is this an expected result or are we making a mistake somewhere :) This result was a great and pleasing surprise for us.

without Ivy with Ivy Reduce (%)
11,6 MB 3,72 68
1248877 MB 344095 72

alialtun14 avatar Feb 09 '20 13:02 alialtun14

If your app is working properly, I don't think you've done anything wrong. Your project might be a new record for size savings with Ivy :D

filipesilva avatar Feb 09 '20 14:02 filipesilva