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
It seems to be indeed the @angular-builders/custom-webpack:browser that causes the slow down π²
ng build --watch
- with @angular-devkit/build-angular:browser
Initial Chunk Files | Names | Size
vendor.js | vendor | 7.86 MB
main.js | main | 6.66 MB
scripts.js | scripts | 677.03 kB
polyfills.js | polyfills | 213.39 kB
styles.css | styles | 150.33 kB
runtime.js | runtime | 14.33 kB
| Initial Total | 15.55 MB
Build at: 2021-07-01T11:06:38.058Z - Hash: cd684dc7fcbc67560f0f - Time: 76208ms
- with @angular-builders/custom-webpack:browser
Initial Chunk Files | Names | Size
vendor.js | vendor | 6.67 MB
main.js | main | 6.66 MB
scripts.js | scripts | 677.03 kB
polyfills.js | polyfills | 213.39 kB
styles.css | styles | 150.33 kB
runtime.js | runtime | 13.67 kB
| Initial Total | 14.36 MB
Build at: 2021-07-01T11:43:51.105Z - Hash: 34bdac20b292943b28c9 - Time: 107267ms
β Browser application bundle generation complete.
β Index html generation complete.
15 unchanged chunks
Build at: 2021-07-01T11:44:36.147Z - Hash: e7860c484b03f51d78f9 - Time: 43856ms
- with @angular-builders/custom-webpack:browser and without custom terser config in the referenced webpack config
Initial Chunk Files | Names | Size
vendor.js | vendor | 6.67 MB
main.js | main | 6.66 MB
scripts.js | scripts | 677.03 kB
polyfills.js | polyfills | 213.39 kB
styles.css | styles | 150.33 kB
runtime.js | runtime | 13.67 kB
| Initial Total | 14.36 MB
Build at: 2021-07-01T11:12:49.818Z - Hash: 1ac2e18b2a871e0bf8a0 - Time: 103078ms
β Browser application bundle generation complete.
β Index html generation complete.
15 unchanged chunks
Build at: 2021-07-01T11:13:32.438Z - Hash: b8d53eea43833e670b2b - Time: 41681ms
- with @angular-builders/custom-webpack:browser with empty webpack config
Initial Chunk Files | Names | Size
vendor.js | vendor | 7.86 MB
main.js | main | 6.66 MB
scripts.js | scripts | 677.03 kB
polyfills.js | polyfills | 213.39 kB
styles.css | styles | 150.33 kB
runtime.js | runtime | 13.67 kB
| Initial Total | 15.55 MB
Build at: 2021-07-01T11:17:38.033Z - Hash: 223bbb0d807f62d6e34f - Time: 109983ms
β Browser application bundle generation complete.
β Index html generation complete.
15 unchanged chunks
Build at: 2021-07-01T11:18:26.881Z - Hash: b76731d2fe86fcc023e6 - Time: 47707ms
btw this is the custom webpack config:
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
externals: {
'fabric': 'window'
},
plugins: [new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en|de/)],
optimization: {
minimizer: [new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: true,
keep_fnames: false,
safari10: false
},
})]
}
};
Conclusion:
- with the default angular builder a. times are the same as with v11 (or even a bit better) b. there is no immediate recompile on watch π₯³
- with the custom-webpack builder a. it takes much longer even if the custom webpack config does not contain anything b. bundle is quite a bit smaller because of moment locale exclusion
However... we need the custom webpack config as we do not want to have all the unnecessary moment locales in our bundle and also need to be able to specify 'fabric' as external for some legacy lib we are using. So I guess I will head over to the @angular-builders/custom-webpack:browser project and file an issue there. Thanks a lot @alan-agius4 !
Success! I found steps to get good performance when using @angular-builders/custom-webpack
TLDR; before upgrading angular, remove all traces of custom-webpack so the migrations run in full, and then re-install custom-webpack
Here is what worked for me, starting with an Angular 11 project:
- In angular.json, replaced all traces of
@angular-builders/custom-webpack:browserwith@angular-devkit/build-angular:browser(and delete thecustomWebpackConfigblock) - Removed
@angular-builders/custom-webpackfrom package.json - Deleted
node_modulesandpackage_lock.json - Ran
npm install - Ran
ng update @angular/cdk @angular/cli @angular/core - Added v12 of
@angular-builders/custom-webpackback into package.json - Ran
npm install - In angular.json, changed back to
@angular-builders/custom-webpack:browserand restored thecustomWebpackConfigblock.
I confirmed that the migrations in angular.json (that were getting skipped) make the difference (2x slower ng serve build time)
Benchmarking gives similar results as with angular 11 and markedly better results when I use NG_PERSISTENT_BUILD_CACHE=1
Like @mrucelum our project uses @angular-builders/custom-webpack to specify several packages as externals (legacy code needs the package as well, so don't want to double load them) Is there any chance ng update could do migrations when custom-webpack is in use? Or the ability to specify external packages without using custom-webpack? Thanks everyone for the info that lead me to this solution!
@mrucelum Thanks for all the stats. I'm actually using @angular-builders/custom-webpack:browser too and for the exact same reason (moment.js size). However I just ran a dozen builds and with or without the custom builder it was taking 38-40 seconds each time. And it definitely did change because it told me to remove the part of the config that was due to the custom builder.
However... as I was writing this though I saw you managed to get them working.....
But, could you confirm that running the migrations did not in fact disable AOT compilation in your angular.json file. Depending upon your exact version of the CLI it's possible to end up disabling it when running migrations (due to a change in what was considered the default). If you in fact did disable AOT then that would explain the much faster compilation. Again though I'm using the same builder and wasn't seeing any noticeable difference between them. (Also version 12.1.0 of the custom builder was just published today - not sure if there were changes or just a version bump)
NG_BUILD_CACHEis enabled by default, and is mainly used to opt-out all build caching, this supersedesNG_PERSISTENT_BUILD_CACHE.NG_PERSISTENT_BUILD_CACHEis disable by default, and can be used to opt-in to cache the entire build on disk, which will make the 2nd build warm. Typically you don't want this on CI since typically the "cache" will be discarded withnode_modulesafter every CI run.That being said, this issue is about build times and not memory, hence if you are experiencing memory issues please file a new issue providing all the necessary profiles and/or a reproduction.
Thanks @alan-agius4 for the explanation and sorry you'll probably end up marking this "off topic", but maybe not since it is about NG_PERSISTENT_BUILD_CACHE and I do care about any build speed improvements I can get since my build does seem slow to me.
I reviewed https://github.com/angular/angular-cli/pull/20756 to confirm I understood and I wasn't taking a corner case that was unexpected. I use NG_BUILD_CACHE to point to a directory that is external to the node modules and in a location the CI will preserve, and this looks like it's still OK to do based on https://github.com/angular/angular-cli/blob/736a5f89deaca85f487b78aec9ff66d4118ceb6a/packages/angular_devkit/build_angular/src/utils/environment-options.ts#L70-L81 does that mean I should also be able to turn on NG_PERSISTENT_BUILD_CACHE in order to persist the webpack cache? I noticed this was said to be experimental, but any reason I might not want to turn it on in this context? It looks like the cache key is pretty comprehensive and I would think the serialized build options should probably be good :thinking:
Edit: After thinking about it more I definitely have places I can enable NG_PERSISTENT_BUILD_CACHE and hopefully it speeds up those paths, so thanks again regardless!
This actually looks to really help a lot for my build time :tada: , but I've found a few errors and I'm reporting them (and fixing the one I can fix simply)
After upgrading from Angular 11 to Angular 12 the build time went up from ~1 second to 22 seconds π€―
https://github.com/whyboris/Video-Hub-App/pull/648
@whyboris It doesn't for me:
Is there a particular change I should be making?
@JoostK thank you for testing! I was so frustrated I quit for the day, but thanks to your message I had new hope π
I ran rm -rf node_modules and npm install again ~and it looks like I'm back to fast~ π
Build at: 2021-07-07T20:46:38.298Z - Hash: f2c33b8ef37564ec1ef0 - Time: 1713ms π
~Sorry for the scare~ π
update: π€¦ turns out it still takes ~22 seconds when you just add console.log in some component
@whyboris Thanks for getting back. Good to hear it's fast again, hopefully it stays that way. If you do run into it again please report back so we can have another look.
@JoostK π€¦ sorry -- the reload was fast because I simply saved the file with no changes ... but when I add console.log somewhere - thereby changing the file, the compilation takes a long time again:
Build at: 2021-07-07T20:50:32.591Z - Hash: 0a430155980e29d73d08 - Time: 23324ms π’
It seems to hang on the ... bundles (phase: sealing)... step
@whyboris Oh, it's just a misconfiguration. In Angular 12 some builder defaults have changed in support of the new production builds by default for ng build. I am not sure how you updated but I don't see any changes to angular.json in the pull request; ng update should have updated it to pin the configuration options to their prior defaults to retain the previous behavior. If I run ng update @angular/cli --migrate-only --from 11 --to 12 then the angular.json file is indeed updated. Please review the changes as I notice in your case that aot will be set to false, which may or may not be desirable.
@JoostK thank you very much for the suggestion!
I went back to my main branch (before my attempt to upgrade to angular 12) and ran the command you gave:
ng update @angular/cli --migrate-only --from 11 --to 12
It updated my angular.json file and now the app recompiles quickly after every save π
https://github.com/whyboris/Video-Hub-App/pull/666/files
Thank you π€ π β€οΈ
@whyboris it seems like you set "aot": false which should be set to true (if I'm not misstaken)
Just wanted to let you know that I did the migration again the way @DavidBowdoin suggested (remove custom builder before ng update). Aaaand there is no slowdown anymore! π₯³
Not sure what the issue was, maybe it was actually fixed with the newest version of the custom webpack builder (as @simeyla suggested). My angular.json was not touched by the migration at all (although I removed the custom builder before the migration!), so I guess that was not the problem.
But anyway, I am happy that we can update now! Thanks again everyone! :)
Maybe this can solve this problem https://dev.to/brandontroberts/speeding-up-the-development-serve-after-upgrading-to-angular-v12-5db5
It appears that the root cause of the problem is misconfigurations and not an issue in the Angular CLI.
If you are still experiencing slow production builds please open a new issue with a production.
Removing "emitDecoratorMetadata": true from tsconfig.json reduced our build time significantly for production.
Success! I found steps to get good performance when using
@angular-builders/custom-webpackTLDR; before upgrading angular, remove all traces of
custom-webpackso the migrations run in full, and then re-installcustom-webpackHere is what worked for me, starting with an Angular 11 project:
- In angular.json, replaced all traces of
@angular-builders/custom-webpack:browserwith@angular-devkit/build-angular:browser(and delete thecustomWebpackConfigblock)- Removed
@angular-builders/custom-webpackfrom package.json- Deleted
node_modulesandpackage_lock.json- Ran
npm install- Ran
ng update @angular/cdk @angular/cli @angular/core- Added v12 of
@angular-builders/custom-webpackback into package.json- Ran
npm install- In angular.json, changed back to
@angular-builders/custom-webpack:browserand restored thecustomWebpackConfigblock.I confirmed that the migrations in angular.json (that were getting skipped) make the difference (2x slower ng serve build time)
Benchmarking gives similar results as with angular 11 and markedly better results when I use NG_PERSISTENT_BUILD_CACHE=1
Like @mrucelum our project uses @angular-builders/custom-webpack to specify several packages as externals (legacy code needs the package as well, so don't want to double load them) Is there any chance ng update could do migrations when custom-webpack is in use? Or the ability to specify external packages without using custom-webpack? Thanks everyone for the info that lead me to this solution!
This solved my issue! Thanks :)
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.