angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.68k stars 11.98k forks source link

Out of memory after upgrade to latest version #27633

Closed fmancuso closed 1 week ago

fmancuso commented 2 months ago

Command

build

Is this a regression?

The previous version in which this bug was not present was

12

Description

After upgrading from angular 12 to angular 17 the build command started to go in Out of memory.

Minimal Reproduction

I cannot provide a minimal reproduction as I would have to upload my entire project.

Exception or Error

I tried to build with a --max-old-space-size=12000 and there is the log after the OOM error:
<--- Last few GCs --->

[69393:0x7feef0100000]   214299 ms: Mark-Compact 11821.8 (12037.0) -> 11819.9 (12036.0) MB, 4539.15 / 0.00 ms  (average mu = 0.277, current mu = 0.034) allocation failure; scavenge might not succeed
[69393:0x7feef0100000]   220253 ms: Mark-Compact 11835.7 (12036.0) -> 11833.9 (12066.0) MB, 5930.46 / 0.00 ms  (average mu = 0.139, current mu = 0.004) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1052b5b15 node::Abort() [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 2: 0x1052b5cf6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 3: 0x105468d6c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 4: 0x105658e07 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 5: 0x105657669 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 6: 0x10564bed1 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 7: 0x10564c915 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 8: 0x10562ea02 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
 9: 0x105aac5e0 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/francesco.mancuso/.nvm/versions/node/v20.9.0/bin/node]
10: 0x68d39a536
11: 0x68d33dd72.

Your Environment

Previous versions:
Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1200.4
@angular-devkit/build-angular      0.1000.5
@angular-devkit/build-ng-packagr   0.1000.5
@angular-devkit/core               12.0.4
@angular-devkit/schematics         12.0.4
@schematics/angular                12.0.4
ng-packagr                         10.0.3
rxjs                               6.5.5
typescript                         4.2.3
zone.js                               0.10.3

Actual version:
@angular-devkit/architect       0.1703.7
@angular-devkit/build-angular   17.3.7
@angular-devkit/core            17.3.7
@angular-devkit/schematics      17.3.7
@angular/cli                    17.3.7
@schematics/angular             17.3.7
ng-packagr                      17.3.0
rxjs                            7.4.0
typescript                      5.3.3
zone.js                         0.14.5

Anything else relevant?

The components and the various file in the project are the same. Previous the upgrade the maximum quantity of RAM that the process took up was 4 GB now it grows without limits. I tried to take a memory heap dump but without success as the dump was getting stuck

alan-agius4 commented 2 months ago

Unforunyley without a memory snapshot there is nothing that we can inveiagte, ou can generate a memory snapshot by uisig the below command.

node --heapsnapshot-near-heap-limit=1 node_modules/@angular/cli/lib/init.js build
fmancuso commented 2 months ago

I tried with the node options to create heap snapshot but it create an empty file

fmancuso commented 2 months ago

After 2 hours the empty file became a 5GB file, you can find it here: https://drive.google.com/file/d/1lpiqn4R6q7o3BIAix8LtlsFYW8n_QKJx/view?usp=drive_link

Edit: I tried to open the heap snapshot but it gave me error. I tried running the command: node --heap-prof node_modules/@angular/cli/lib/init.js build and I attach the generated .heapprofiles here: Heapprofile.zip

rlindgren commented 2 months ago

+1 Here for this as well

jpike88 commented 2 months ago

I've noticed builds are slower and it's more memory hungry too, multiple reloads over time cause heavy memory pressure. the Facebook team is rewriting the react compiler in rust, maybe it's time to consider doing the same here... I am using biomejs instead of eslint and the difference in memory/cpu usage was dramatic.

ZissisT commented 1 month ago

This happens to me when no package-lock.json. Did you update npm as well? https://github.com/npm/cli/issues/7276

Edit: Sorry for any confusion, I get the same out of memory error during npm install, not building, so ignore my comment

fmancuso commented 1 month ago

In my case it turned out to be a problem due to the change from node-sass to sass. I had to replace a lot of the @import with @use as suggested by sass, the amount of RAM has decreased a lot, it still continues to be slower than before the upgrade. Before the upgrade the build went up to a maximum of 4gb now it goes up to 5.5gb in fact I had to pass the option --max-old-space-size=8192 to avoid problem. In any case I would investigate why there is this increase in RAM required.

I hope it can be useful to someone.

alan-agius4 commented 1 week ago

Closing because it seems the issue has been resolved.