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

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

We started using in production after compiled. There were a few problems we encountered during the compilation. We fixed the problems with your support.

alialtun14 avatar Feb 09 '20 15:02 alialtun14

@filipesilva I am not sure if it is related to this issue but:

I am getting this error in CircleCI. But it builds perfectly in local or Heroku. CLI version: 9.0.2

ERROR in main.5e6bd3ca7eb1cdef2086.js from Terser
Error: Call retries were exceeded
    at ChildProcessWorker.initialize (/home/circleci/workspace/app-web/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/workers/ChildProcessWorker.js:230:21)
    at ChildProcessWorker._onExit (/home/circleci/workspace/app-web/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/workers/ChildProcessWorker.js:307:12)
    at ChildProcess.emit (events.js:223:5)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)

Disabling optimization works but it is not desirable.

Things I tried and did not work:

  • Using --max_old_space_size=4096 / 8192
  • Node versions: 10.x, 12.x, 13.x
  • Disabling source maps
  • Disabling differential loading. I got the same error but the place where I got the error changed.

I see that terser has a problem with CircleCI and it is recommended to use parallel option. But I don't know how to do that in Angular. Related links:

https://github.com/webpack-contrib/terser-webpack-plugin#parallel https://github.com/webpack-contrib/terser-webpack-plugin/issues/202#issuecomment-580704210

gkurt avatar Feb 13 '20 13:02 gkurt

@KurtGokhan we use the parallel option but let terser-webpack-plugin figure out the real count, and this seems to be a problem in CircleCI. Maybe we should limit the maximum to get around this problem...

filipesilva avatar Feb 14 '20 10:02 filipesilva

@KurtGokhan https://github.com/angular/angular-cli/pull/16978 should help with that problem.

filipesilva avatar Feb 14 '20 15:02 filipesilva

@filipesilva I tested a build from your branch and it works while the master branch build fails. Thank you.

Meanwhile I switched to Github Actions and it works correctly as well.

gkurt avatar Feb 17 '20 15:02 gkurt

@filipesilva I'm running into the same problem

Generating ES5 bundles for differential loading...
An unhandled exception occurred: Call retries were exceeded

When building the app in a gitlab kubernetes runner.

Node: v12 Angular:

Angular CLI: 9.0.1
Node: 12.16.0
OS: darwin x64

Angular: 9.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-angular     0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/build-webpack     0.900.1
@angular-devkit/core              9.0.1
@angular-devkit/schematics        9.0.1
@angular/cli                      9.0.1
@angular/flex-layout              9.0.0-beta.28
@ngtools/webpack                  9.0.1
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.3
typescript                        3.7.5
webpack                           4.41.2

Zwartpet avatar Feb 19 '20 12:02 Zwartpet

I think it would help if I can limit the number fixed in https://github.com/angular/angular-cli/pull/16978 as 7 is still to much for a container

Zwartpet avatar Feb 19 '20 13:02 Zwartpet

Agreed, @filipesilva it would be great if we can configure the parallel value ourselves since Circle still fails out with max retries after your fix was installed.

gnomeontherun avatar Feb 19 '20 19:02 gnomeontherun

@Zwartpet I think the error you are seeing is not the same as the one mentioned above. That is because downlevelling happens after running the Webpack build.

This issue is mostly caused by JestWorker usage in https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/utils/action-executor.ts. JestWorker uses the following logic to determine the number of workers to spawn https://github.com/facebook/jest/blob/fa8ef2269ceb52ee1bec2e77ba4358dd4ade85b2/packages/jest-worker/src/index.ts#L80

alan-agius4 avatar Feb 20 '20 09:02 alan-agius4

@alan-agius4 But why not make it configurable? I doubt that this will resolve the issue as it still spawns more workers then I there is room for in a container.

But let me test it before i make an assumption

Zwartpet avatar Feb 20 '20 10:02 Zwartpet

@filipesilva CircleCI build is working with the new patch.

Apart from that, builds take longer time on CI with Ivy. Because ngcc compiler runs every time. Is there a way to cache ngcc compiling result? Which folders should be cached?

What I mean is this part:

Compiling @angular/core : es2015 as esm2015

Compiling @angular/common : es2015 as esm2015

Compiling @angular/platform-browser : es2015 as esm2015
...

gkurt avatar Mar 02 '20 18:03 gkurt

Everything is compiled into the node_modules directory, so that should be cached.

There’s a npm/yarn postinstall command you can use (and tweak) on: https://angular.io/guide/ivy

On 2 Mar 2020, at 19:10, Gökhan Kurt [email protected] wrote:

 @filipesilva CircleCI build is working with the new patch.

Apart from that, builds take longer time on CI with Ivy. Because ngcc compiler runs every time. Is there a way to cache ngcc compiling result? Which folders should be cached?

What I mean is this part:

Compiling @angular/core : es2015 as esm2015 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Zwartpet avatar Mar 02 '20 19:03 Zwartpet

Everything is compiled into the node_modules directory, so that should be cached. There’s a npm/yarn postinstall command you can use (and tweak) on: https://angular.io/guide/ivy

I was using npm ci, which deleted node_modules. Switched to npm i and workflow got a lot faster.

gkurt avatar Mar 03 '20 05:03 gkurt

@dgp1130 in #17027 you said:

If you're still seeing memory issues after that is merged and released, then we can reevaluate.

I use last version of angular-cli and still have erros like in this comment (https://github.com/Automattic/wp-calypso/pull/39535#issuecomment-589603920): Error: Call retries were exceeded and Error: write EPIPE.

Could you add option to configure parallel in terser?

Semigradsky avatar Apr 03 '20 06:04 Semigradsky

Our project is also facing difficuilties to use ngcc.

ng version reads:

Angular CLI: 9.0.7                                                          
Node: 13.12.0                                                               
OS: win32 x64                                                               
                                                                            
Angular: 9.0.7                                                              
... animations, cli, common, compiler, compiler-cli, core, forms            
... language-service, platform-browser, platform-browser-dynamic            
... router                                                                  
Ivy Workspace: Yes                                                          
                                                                            
Package                            Version                                  
------------------------------------------------------------                
@angular-devkit/architect          0.900.7                                  
@angular-devkit/build-angular      0.900.7                                  
@angular-devkit/build-ng-packagr   0.900.7                                  
@angular-devkit/build-optimizer    0.900.7                                  
@angular-devkit/build-webpack      0.900.7                                  
@angular-devkit/core               9.0.7                                    
@angular-devkit/schematics         9.0.7                                    
@angular/cdk                       9.1.3                                    
@angular/flex-layout               9.0.0-beta.29                            
@angular/material                  9.1.3                                    
@ngtools/webpack                   9.0.7                                    
@schematics/angular                9.0.7                                    
@schematics/update                 0.900.7                                  
ng-packagr                         9.0.3                                    
rxjs                               6.5.4                                    
typescript                         3.7.5                                    
webpack                            4.41.2                             

command: npm ci

We tried to remove node_modules folder manually several times but get same results. It always stops during the same point in the compilation.

Paths has been partly edited manually from the stacktrace using , <ProjectPath> and <UserPath>:

Compiling ngx-papaparse : esm5 as esm5
Compiling ngx-papaparse : main as umd
Compiling angular-tree-component : module as esm5

<--- Last few GCs --->

[265432:00000228019FF580]   147212 ms: Scavenge 2045.6 (2050.4) -> 2045.1 (2050.7) MB, 11.3 / 0.0 ms  (average mu = 0.287, current mu = 0.344) allocation failure
[265432:00000228019FF580]   147280 ms: Scavenge 2045.8 (2050.7) -> 2045.3 (2050.7) MB, 11.2 / 0.0 ms  (average mu = 0.287, current mu = 0.344) allocation failure
[265432:00000228019FF580]   147323 ms: Scavenge 2046.0 (2050.7) -> 2045.8 (2051.4) MB, 11.5 / 0.0 ms  (average mu = 0.287, current mu = 0.344) allocation failure


<--- JS stacktrace --->

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

Security context: 0x036698280921 <JSObject>
    0: builtin exit frame: parse(this=0x03669829efd9 <Object map = 00000204FC003641>,0x0053ab6fa1a1 <Very long string[18219]>,0x03669829efd9 <Object map = 00000204FC003641>)

    1: loadSourceMap [000000619C56E339] [<ProjectPath>\node_modules\@angular\compiler-cli\ngcc\src\sourcemaps\source_file_loader.js:~73] [pc=000000D88484CC61](this=0x0030c61c46a9 <SourceFileLoader map = 00000204FC01...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF69ABE0B5F napi_wrap+110655
 2: 00007FF69AB8C606 v8::base::CPU::has_sse+67398
 3: 00007FF69AB8D3F4 v8::base::CPU::has_sse+70964
 4: 00007FF69B3B20BE v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF69B399811 v8::SharedArrayBuffer::Externalize+785
 6: 00007FF69B26087C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
 7: 00007FF69B26BBC0 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF69B2686B4 v8::internal::Heap::PageFlagsAreConsistent+3188
 9: 00007FF69B25DDC3 v8::internal::Heap::CollectGarbage+1283
10: 00007FF69B25C554 v8::internal::Heap::AllocateExternalBackingStore+1396
11: 00007FF69B285908 v8::internal::Factory::NewRawOneByteString+216
12: 00007FF69B1A39B0 v8::base::TimeDelta::operator!=+31184
13: 00007FF69B1A4B4C v8::base::TimeDelta::operator!=+35692
14: 00007FF69B1A3EFA v8::base::TimeDelta::operator!=+32538
15: 00007FF69B329190 v8::internal::Builtins::builtin_handle+83856
16: 00007FF69B32973E v8::internal::Builtins::builtin_handle+85310
17: 00007FF69B7FBCCD v8::internal::SetupIsolateDelegate::SetupHeap+517677
18: 000000D88484CC61
Warning: Worker #5 exited unexpectedly (code: 134 | signal: null).
  Current assignment: {entryPoint: angular-draggable-droppable, formatProperty: main, processDts: false}
Error: Process unexpectedly crashed, while processing format property main for entry-point '<ProjectPath>/node_modules/angular-draggable-droppable'.
    at ClusterMaster.onWorkerExit (<ProjectPath>\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:152:23)
    at <ProjectPath>\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:50:101
    at ClusterMaster.<anonymous> (<ProjectPath>\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:245:57)
    at step (<ProjectPath>\node_modules\tslib\tslib.js:139:27)
    at Object.next (<ProjectPath>\node_modules\tslib\tslib.js:120:57)
    at <ProjectPath>\node_modules\tslib\tslib.js:113:75
    at new Promise (<anonymous>)
    at Object.__awaiter (<ProjectPath>\node_modules\tslib\tslib.js:109:16)
    at EventEmitter.<anonymous> (<ProjectPath>\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:239:32)
    at EventEmitter.emit (events.js:315:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <ProjectName>@0.0.0 postinstall: `ngcc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <ProjectName>@0.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

nac0n avatar Apr 03 '20 09:04 nac0n

@nac0n - I believe that your issue is because there is a circular dependency within the source-map - source tree, which ngcc is not handling well. Tracking at FW-2041. The description in that issue is:

In the ngcc-validation project we have noted that angular-draggable-droppable causes ngcc to crash with a stack-overflow when processing the UMD format!

This is because the source-map for this file contains inline source content that is has a source-map comment that references the original source-code. There is already cycle detection in the source-map loading algorithm but it only covers case where the source file is loaded more than one, creating a cycle. In this case the source is not loaded from a path on disk but is internal to the source-map itself, so it is not being caught and an infinite recursion is happening.

The proposed solution is to track the paths to the source-map files in addition to the paths to the source files.

I'll see if we can bump it up the priority queue.

petebacondarwin avatar Apr 03 '20 09:04 petebacondarwin

@petebacondarwin - I see, we'll have the postinstall script and other occurrences with angular-draggable-droppable disabled for the time being if we can and will keep ourselves updated looking for fixes to it then. Thanks for the response.

Edit: I do not have access to that issue tracking, just a note. However, i trust that the information about the bugfix will reach consumers.

nac0n avatar Apr 03 '20 10:04 nac0n

@nac0n - The fix to be more resilient to cycles in source-maps was landed in 9.1.1 - https://github.com/angular/angular/pull/36452

petebacondarwin avatar Apr 10 '20 15:04 petebacondarwin

i am installing angular material and getting error and I think this is due to angular cli version 9

faisalzamankhan avatar Apr 12 '20 06:04 faisalzamankhan

Initial ng build ("Compiling ... es2015 as esm2015") requires 4GB of ram for a fresh empty app with angular material (all latest). Is this really normal? :|

LastDragon-ru avatar Apr 16 '20 10:04 LastDragon-ru