Buildtime increased by 50% in v12
π Bug report
Command (mark with an x)
- [x] build
Description
This is v11.2.13:
$ ng build --prod
β Browser application bundle generation complete.
β Copying assets complete.
β Index html generation complete.
Initial Chunk Files | Names | Size
main.1bbe17e891e0e81a6bae.js | main | 3.20 MB
scripts.5b3322e07a3cdcf6af69.js | scripts | 1.48 MB
styles.19406af932cc90ae2667.css | styles | 152.44 kB
polyfills-es5.2cb7395a5fd592fe7443.js | polyfills-es5 | 85.88 kB
runtime.23c71f07ba7ec5c3766a.js | runtime | 1.51 kB
| Initial Total | 4.92 MB
Build at: 2021-05-14T11:00:10.476Z - Hash: 034e3176df64cbc0b60a - Time: 88357ms
Verbose log (logging itself causes slowdown, unfortunately...): angular11.txt
Angular CLI: 11.2.13
Node: 14.17.0
OS: win32 x64
Angular: 11.2.13
... 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.1102.13
@angular-devkit/build-angular 0.1102.13
@angular-devkit/core 11.2.13
@angular-devkit/schematics 11.2.13
@angular/cdk 11.2.12
@angular/material 11.2.12
@schematics/angular 11.2.13
@schematics/update 0.1102.13
rxjs 6.6.7
typescript 4.1.5
This is v12 with yarn.lock and node_modules removed and reinstalled:
$ ng build --configuration production
Warning: Support was requested for IE 11 in the project's browserslist configuration. IE 11 support is deprecated since Angular v12.
For more information, see https://angular.io/guide/browser-support
β Browser application bundle generation complete.
β Copying assets complete.
β Index html generation complete.
Initial Chunk Files | Names | Size
main.25755cb56d908f1ffa0c.js | main | 3.19 MB
scripts.5b3322e07a3cdcf6af69.js | scripts | 1.48 MB
styles.51baf6c2a9fbe6837aa1.css | styles | 154.28 kB
polyfills-es5.b787b17c5e8d81a4b18e.js | polyfills-es5 | 90.75 kB
runtime.bf3db8034d6e10a74a56.js | runtime | 1.20 kB
| Initial Total | 4.92 MB
Build at: 2021-05-14T11:18:16.175Z - Hash: 8806f0a3a3b1271495e0 - Time: 157125ms
Verbose log (logging itself causes slowdown, unfortunately...): angular12.txt
Angular CLI: 12.0.0
Node: 14.17.0
Package Manager: yarn 1.22.5
OS: win32 x64
Angular: 12.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1200.0
@angular-devkit/build-angular 12.0.0
@angular-devkit/core 12.0.0
@angular-devkit/schematics 12.0.0
@schematics/angular 12.0.0
rxjs 6.6.7
typescript 4.2.4
We have a single small *.scss file (overriding some material colors) and it was updated by migration. The application has only one module. I tried removing scss and css from angular.json, but it is still slower than v11.
On average it is 50% slower.
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 1011 10391 2652 54543
HTML 311 629 7 7832
CSS 66 344 30 2109
Sass 1 15 14 63
JavaScript 1 9 3 55
JSON 1 0 0 3
-------------------------------------------------------------------------------
SUM: 1391 11388 2706 64605
-------------------------------------------------------------------------------
Recorded profile using node 12:
https://link.nithins.me/s2Uca0Ti
@alan-agius4 Yet, that's the one. This is how it looks when I load it in Chrome's Node.js DevTools:

Which tool are you using?
Chromeβs profiler
I'm doing the following:
- Open chrome://inspect
- Click the Open dedicated DevTools for Node link
- Click Load and select the file
@cypressious, I re-downloaded the file from Dropbox and now I can see the same thing. Will investigate this more tomorrow.
That gap is the time taken by terser (the JS optimizer). Webpack runs terser in workers which causes the main thread to remain idle while the optimizer works since there is nothing left for the build process to do at that point (barring the final write to disk).
Why do we need optimization in dev mode?
Why do we need optimization in dev mode?
So I have been wondering whether the switch to prod builds by default could have affected development builds. I believe that the CLI performs a migration of angular.json to switch the builder options to be targeting development mode as before, but maybe there are cases where the project ends up being misconfigured.
A production (or development) build is defined purely by the options present in the configuration section. If the above build was not intended to be a production build then the project configuration may be incorrect.
Are you using 3rd party builders by any chance?
The production by default migration is actually an opt-in migration.
What is happening here is probably one of below things.
ng-updatewas run multiple times, one of the migrations is non-idempotent. Which will cause the project to be miss configured if run multiple times.- The migration was not run because you are using unofficial builders which cause un-desired behaviour. In which case, we cannot know how these builders interact with the builder options and therefore we cannot modify the configuration. As such it is recommend that such builders provide their own ng-update migration or at least document what needs to change for version 12.
The migration I am referring too is https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-12/update-angular-config.ts
Thank you for ideas.
I didn't run ng-update on the project in question. I was under the impression that upgrading the dependencies in the package.json was enough. My bad. I'll try reverting and running ng-update and will report back if it helped.
The https://update.angular.io site can provide update instructions and guidance when updating between Angular versions.
When doing the ng update, I also noticed that it added production by default but it never added these to build/serve and I had to add them myself:
"defaultConfiguration": "development"
production by default is an optional migration. The migration that is run automatically adjusts the options to maintain the previous development by default behavior because several of the options had default values swapped.
As for the source mapping performance regression: I tracked it down to a change in Webpack 5 and opened webpack/webpack-sources#109, which implements a proposal to resolve the regression. I'm not sure if the changes in that PR are entirely desirable so we'll see where it gets us.
Can anyone show me how to use NG_BUILD_CACHE=0, where to add this parameter? I am also getting crashes after upgrading to 12.0.1, build time is much longer and getting crashes due to memory issue.
I can confirm that following the upgrade instructions migrated the angular.json and fixed the problem.
For those interested, it added
"aot": false,
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
to projects.app.architect.build.options.
I can confirm that following the upgrade instructions migrated the
angular.jsonand fixed the problem.For those interested, it added
"aot": false, "vendorChunk": true, "extractLicenses": false, "buildOptimizer": false, "sourceMap": true, "optimization": false, "namedChunks": trueto
projects.app.architect.build.options.
I had the same config except aot:false , aot is defaulted to true, and it worked no problem in V11, why should we turn it off in V12?
The migration adjusts the options to provide equivalent behavior from prior to the update. The new/adjusted set of options and their values may be different for each project depending on the starting options. If AOT was enabled before, it will continue to be enabled afterwards but without the option present since the default is now true.
The recommended way is "aot": true (or not set) => since it is de default.
Right?
When I migrated my AOT was true before and set to false. I had to manually set it back to true. But guess I'd need to create a separate repository/reproduction to prove it