v7.0.0 bugs and 4/5x slower serve & compile AOT
I hesitate to open this issue on angular page. I opened same issue title 2 week ago here without AOT : v7.rc.0 serving 2x - 3x slower than stable versions on my projects after moving to angular 7.0.0 all is slower (jit seems OK)
I'm submitting a...
[ x ] Performance issue [ x ] Bugs
Current behavior
All was OK with cli7rc3 and angular 6.1.10 This morning after updating to angular 7.0.0 serving with JIT is ok but serving with AOT or build my application or generating i18n xmb file is 2-3 times slower
Expected behavior
Get build/extract i18n time like with cli7rc3 and angular 6.1.10
1. Minimal info of AOT serving
- My project have >1200 files.
- Before update
node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng serve --aot --sourceMap=false --disableHostCheck --port=4200first build finish in 45seconds and Now blocking:
3mn =>
11% building modules 9/10 modules 1 active ...ojects\i10\src\assets\styles\styles.cssand rest steps seems ok It finish in 228737ms
- Before update refresh(file edit) it finish in 30seconds and 3th refresh in 25seconds and Now it refresh in 200277ms and 3th refresh in WARNING : 381979ms it is >6 minutes
2. Minimal info of extract i18n
- Extract is 3-4 times slower than before update
Here is my angular.json config file
I tried debug with ndb and share my profile data with ng s --aot but it seems not work ndb crash ( disk is highly used...):

Environment
Angular CLI: 7.0.1
Node: 10.12.0
OS: win32 x64
Angular: 7.0.0
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.10.1
@angular-devkit/build-angular 0.9.0-rc.3
@angular-devkit/build-optimizer 0.9.0-rc.3
@angular-devkit/build-webpack 0.9.0-rc.3
@angular-devkit/core 7.0.1
@angular-devkit/schematics 7.0.1
@angular/cdk 6.4.7
@angular/cli 7.0.1
@angular/material 6.4.7
@ngtools/webpack 7.0.0-rc.3
@schematics/angular 7.0.1
@schematics/update 0.10.1
rxjs 6.3.3
typescript 3.1.3
webpack 4.19.1
Others: maybe related to : https://github.com/angular/angular/issues/26572 , https://github.com/angular/angular-cli/issues/12645
@filipesilva heya, sorry to make noise again if you consider this as angular compiler problem(as I think) close or move it please
I have tried just released angular-cli 7.0.4 and TypeScript 3.1.5. Build times are great. But second rebuild in ng serve results in out of memory error.
After first build a have 1GB memory usage by node.js process, after the second one its 1.4 Gb and third rebuild is OOM. Between each build I just commented one line in one ts file.
PS: I have remove node_modules and yarn.lock to ensure correct testing
Angular CLI: 7.0.4 Node: 10.6.0 OS: win32 x64 Angular: 7.0.2 ... animations, cdk, common, compiler, compiler-cli, core, forms ... language-service, material, platform-browser ... platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.10.4 @angular-devkit/build-angular 0.10.4 @angular-devkit/build-optimizer 0.10.4 @angular-devkit/build-webpack 0.10.4 @angular-devkit/core 7.0.4 @angular-devkit/schematics 7.0.4 @angular/cli 7.0.4 @angular/flex-layout 7.0.0-beta.19 @ngtools/webpack 7.0.4 @schematics/angular 7.0.4 @schematics/update 0.10.4 rxjs 6.3.3 typescript 3.1.5 webpack 4.19.1
PS2: in my yarn.lock a can see TypeScript 3.1.3 among angular-cli build dependencies. May be TypeScript should be upgraded in cli repo?
Typescript 3.1.6 has been released to fix https://github.com/Microsoft/TypeScript/pull/28028
[email protected] was just released which should include the performance fix. The combination of @angular/[email protected] and [email protected] should take care of the performance regressions as originally detailed in this issue.
However there are also some reports of a memory leak over rebuilds (@mko, @quanterion), and an odd error about TS program structure (@seangwright). Are these happening only on AOT, or also outside of AOT?
@filipesilva When I change to JIT for ng serve I do not see the The structure of the program changed during codegen. error. It's only during AOT.
I updated to
"@angular/core": "7.0.2",
...
"@angular-devkit/build-angular": "0.10.4",
"@angular/cli": "7.0.4",
...
"typescript: "3.1.6"
and I am no longer seeing the The structure of the program changed during codegen. error. Build times also seem to be far far more reasonable.
My CI build was constantly throwing Out of Memory exceptions, so I'm going to rerun with this package updates to see if it will start working again.
Thanks for all the work on fixing these issues!
This issue was specifically about bundle size and performance, which we think are fixed, and I've noted this in the release notes for https://github.com/angular/angular-cli/releases/tag/v7.0.4
I think we should close this issue, thanks everyone! If there's a memory leak, that's a separate issue and should be opened separately.
Heya, just wanted to mention that I tried to reproduce the memory leak with the new @angular/core and typescript, and couldn't see any. If someone is still experiencing the memory leak please open a new issue and ping me on it.
Back to normal build times with the new CLI 7.0.4 and TypeScript.
"JavaScript heap out of memory" issue is still present in production builds though...
@aalbericio Did you update "@angular/core" to version 7.0.2?
@hakimio Yes, that was all done by ng update but, anyway, I've just double-checked it and I'm in: @angular/[email protected]
with ng build --prod --vendor-chunk --progress false "portal"
Angular CLI: 7.0.4
Node: 11.1.0
OS: linux x64
Angular: 7.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.10.4
@angular-devkit/build-angular 0.10.4
@angular-devkit/build-optimizer 0.10.4
@angular-devkit/build-webpack 0.10.4
@angular-devkit/core 7.0.4
@angular-devkit/schematics 7.0.4
@angular/cli 7.0.4
@ngtools/webpack 7.0.4
@schematics/angular 7.0.4
@schematics/update 0.10.4
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1
Still JavaScript heap out of memory
Same here after full upgrade Angular (7.0.3) and TS (3.1.6) today:
$ ng build --source-map false --project frontend --prod
92% chunk asset optimization TerserPlugin
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
#
#
#FailureMessage Object: 0x7f39243649b0
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
#
#
#FailureMessage Object: 0x7f39253669b0Illegal instruction (core dumped)
If I turn off the optimization in angular.json it's building just fine though.
Same here.
Tested using the same versions described above.
Anyway, our project must be very close to that point where the build can either fail or succeed though. I'd say that it fails 90% of the cases vs 10% of successes.
The question is: is there anything (probably with the TerserPlugin) that can make our build jump the red line of default memory needs?
What has changed in v7 that can make this build cross that line?
Is it expected that we need to allocate more memory for our v7 prod builds?
To be honest I expected terser to require less memory than uglify-es, because of existing bugs that were fixed.
Are you using the additional memory flag? You can use it on a npm script like this:
"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
Increasing the memory limit is something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly.
I wouldn't be terribly surprised if the projects that are now need more memory were nearly at the maximum before, and different code structures ended up demanding more memory...
Also what can happen is that the inner module closures (the module concatenation thing I mentioned before) managed to get more code in a single module and thus require more memory to optimize, with potential better savings.
Filipesilva... Please accept some Angular love

I just came across your comment to fix that issue but it actually fixed way more than that.
Working on a huge project, I had to turn off source maps when building in prod mode (which was a shame because we're reporting our errors to sentry and before we were able to point out where in our TS code the error occurred instead of compiled JS!).
But that's not it. Recently, I got crashes when building prod so I also had to turn off optimization...
And build, serve, linting... Pretty much everything was slow. It's waaaay faster now :heart: :tada: :fire:
Thanks!
Thanks for your clarification, Filipe.
Now that we know that this is an expected behavior, I can now be confident in increasing that memory setting.
I didn't want to do that before since I always expect new versions to be faster, better and use less memory :)
To be honest I expected terser to require less memory than uglify-es, because of existing bugs that were fixed.
@filipesilva No memory improvement was made in terser over uglify-es. Perhaps in the course of fixing bugs the memory requirement may have actually increased in some cases. If you manage to isolate a terser minify() JS input that has significantly larger memory requirements than uglify-es with the same minify options, put the JS in question into a gist and create a new terser issue.
The one dramatic improvement for the minify time regression in collapse_vars was capping the upper bound of quadratic complexity to save CPU time - not memory.
what can happen is that the inner module closures (the module concatenation thing I mentioned before) managed to get more code in a single module and thus require more memory to optimize, with potential better savings
That's probably what's going on. More code was likely fed to terser in a more recent version of webpack or angular-cli. Perhaps there are webpack dials to limit the size of chunks.
Also keep in mind that one must take into account the aggregate memory consumed by angular-cli, webpack and the minifier. Because the minifier is the last to run it often is blamed for problems occurring in earlier phases of the build pipeline. Webpack had several memory problems related to chunks in the past as I recall.
@kzc thanks for chiming in, it's always nice to have your uglify insight!
I kinda assumed that the memory usage came hand in hand with the CPU consumption since as one gets closer to the memory limit more and more time is spent on garbage collection. But I don't really have the logs of any particular project... source files for these bigger projects is hard to come by.
I had a report in https://github.com/angular/angular-cli/pull/11996 of a 60% reduction in build time when moving to terser though. Maybe that was just the regression you mentioned.
Anyway if I come across specific input that exhibits odd resource consumption I'll file an issue.
In regards to the aggregate memory usage, we do use the parallel processing in https://github.com/webpack-contrib/terser-webpack-plugin#parallel. This ends up running individual chunks through terser in a separate process, so the overhead from other tooling is reduced.
However the chunks are rarely of similar size. Most of the time there's a single huge chunk and several small ones. I think the huge chunk is the one that busts the memory limit.
Now that I think about it, I should check if the parent processes memory limit is being passed to the worker processes there...
Here's an example of a webpack process being very close to the Node heap threshold and a webpack + minifier upgrade just put it over the limit: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/188
I kinda assumed that the memory usage came hand in hand with the CPU consumption since as one gets closer to the memory limit more and more time is spent on garbage collection.
True, CPU and memory use are often correlated but minifiers (and probably most optimizing compilers in general) spend the majority of their time looking for optimization opportunities in the AST that may or may not exist. These AST searches don't usually create much in the way of long lived heap objects.
Recent V8 versions reportedly have better GC algorithms, but there also could be regressions in some cases. So it would be worth testing different Node versions when encountering a memory issue.
In my case everything was fine after ng update to v7. But once I updated devDependencies:

the production build time increased about 3 times:
