Build with "ng -prod" is extremely slow
Bug Report or Feature Request (mark with an x)
- [ x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.1.0
node: 7.9.0
os: win32 x64 (Win 10 Enterpirise - 16Gig , i7)
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.1.0
@angular/compiler-cli: 4.0.0
@angular/language-service: 4.0.0
Repro steps.
$ ng build --prod --aot=false -ec --sourcemap=false Hash: 552d9867ececa788ac3a Time: 670222ms chunk {0} polyfills.d77767cee98c83f90386.bundle.js (polyfills) 294 kB {5} [initial] [rendered] chunk {1} main.255e1d27fe4d40b56ab2.bundle.js (main) 1.51 MB {4} [initial] [rendered] chunk {2} scripts.45a4574f31d7b91e5a5e.bundle.js (scripts) 3.88 MB {5} [initial] [rendered] chunk {3} styles.ac17d766c993c4027892.bundle.css (styles) 228 bytes {5} [initial] [rendered] chunk {4} vendor.86c029ec4598fb674488.bundle.js (vendor) 8.23 MB [initial] [rendered] chunk {5} inline.750f0337ff0a9bee9813.bundle.js (inline) 0 bytes [entry] [rendered]
ng build --aot -ec -sm Hash: 24f744145f250126e699 Time: 62809ms chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 294 kB {5} [initial] [rendered] chunk {1} main.bundle.js, main.bundle.js.map (main) 3.07 MB {4} [initial] [rendered] chunk {2} scripts.bundle.js, scripts.bundle.js.map (scripts) 3.88 MB {5} [initial] [rendered] chunk {3} styles.bundle.css, styles.bundle.css.map (styles) 228 bytes {5} [initial] [rendered] chunk {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 7.37 MB [initial] [rendered] chunk {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
670222ms vs 62809ms is a huge difference
The log given by the failure.
There is no failure , the build takes a very long time to complete its stuck at
92% chunk asset optimization and then we have to wait for 10-15 mins to get the build completed.
I have disabled aot and sourcemaps, still the speed is very slow.
Desired functionality.
build should have similar time that to of ng build -aot
Any help and guidance to reduce will be helpful.
Glad to hear it's sorted 👍
I'm having the issue.
Using ng build --prod it finishes in 74112ms.
Using ng build --prod --sourcemaps true it hangs at 92% chuck asset optimization forever (left it running overnight).
Using ng build --prod --sourcemaps true --build-optimizer false, it stops at 92% chunk asset optimization for a few minutes, then hangs at 95% emitting.
CPU at about 80% during chunk asset optimization, then drops to 30% during emitting.
146 .ts 54 .html 6 .css 1 .gitkeep 1 .json
ng --version
Angular CLI: 1.7.2
Node: 8.9.4
OS: win32 x64
Angular: 5.2.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@ angular/cli: 1.7.2
@ angular-devkit/build-optimizer: 0.3.2
@ angular-devkit/core: 0.3.2
@ angular-devkit/schematics: 0.3.2
@ ngtools/json-schema: 1.2.0
@ ngtools/webpack: 1.10.1
@ schematics/angular: 0.3.2
@ schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
currently our application builds with ng build --prod with angular cli 1.7.2 within 2.5 to 3 minutes, but building with ng build --prod --sourcemaps true takes ~7 minutes longer (so ~10 min) - although this is much faster than angular cli 1.6, where build without sourcemaps took ~5-7 minutes and with sourcemaps ~12-15 minutes, it seems like only one part of the build was improved and the large part (source map generation) didn't change.
We are generating source maps for production builds in order to publish them to exception handling services like sentry to rollbar, so it would be really cool if that part could also be improved or made parallel somehow.
FYI I tried again with 1.7.3 and I'm still experiencing "infinite builds" where --sourcemaps true.
I've taken a look at https://github.com/angular/angular-cli/issues/8259 but I'm not 100% sure how to adapt these instructions to working with ng build rather than ng serve.
Just did an upgrade to 1.7.3, and definitely seeing sourcemaps dragging down the build speed. Without sourcemaps, running a prod-build optimizer build takes about 74823ms. Enabling source maps on the exact same build kicks it up to 363124ms, about 5 times longer. Reasonably small project (about 129 source files, using Angular Material, rxjs, flex-layout, date-fns as the main library dependencies).
Wish there was a way to speed up sourcemaps without quintupling the build time.
Unfortunately, to be able to support the necessary optimizations with source maps enabled requires additional functionality to be exposed from within TypeScript itself. There is ongoing work to improve the situation, however, there is currently no timetable at this point.
Well, after spending most of two days making a copy of my project, then stripping modules/components out one at a time to track down the culprit, I got down to 2 feature modules and 1 common module and discovered that doing an ng build --prod -sm has an issue that causes it to hang (at 95% emitting) if any [styleUrls] contain CSS (empty css files are ok).
Looks like this is issue #8314
I put everything back to how I have my production project, modified all my components to not use [styleUrls], then ran ng build --prod -sm and after 4990841ms (83 min), it finally finished.
My /src/app stats are:
145 .ts (approx 10,200 non-blank lines) 55 .html (9.675 non-blank lines) 6 .css
If I also use --build-optimizer false, the time falls to 470616ms (7.8 min)
@alberto-chiesa yes I am sure and it is still the same .Hi @clydin Hope it will be resolved soon
I think that a lot of performance problems will be solved once we can upgrade Webpack to 4.
I saw some quite impressive benchmarks (execution times reduced by 60% to 90%). Unfortunately, this requires some work on many plugins. Nothing major, but there is a lot of small moving parts to be checked and minor fixes for Webpack breaking changes.
1.7.3 still very slow.
1.7.3 fine here. Thanks guys!
Can't move to version 1.7.x due to #9980, so I can't check if the issue was resolved. :-/
I removed my node_modules (I needed a clean up) and updated to CLI 1.7.3 and the problem has come back! The only way I can get a build to complete now is with --build-optimizer=false :tired_face:
I ran into this with production builds (with source maps) hanging at 95% after upgrading to angular-cli 1.7.4 on Windows. Setting --sourcemaps=false, resolved the build issue for me.
@smoses2 Hanging at 95% is a different issue than building slow. For me, I fixed the hanging at 95% issue by switching away from using styleurls - I either embedded the stylesheet in the style property, or added a style link in the page itself. If you're using styleurls, run a test build with them removed.
Do we think this an issue that's going to get fixed in 1.7.x? or is this something that won't get fixed until the next major release?
I removed all styleUrls from my components as a test, and build prod finally ran, but it took about 3 minutes to finish. I added the styleUrls back, and now build prod runs fine again! and in about 10 seconds.
This is really strange
@hahn-kev I imagine they're pretty heads-down trying to get 6.0 out the door before ngConf. Hopefully the switch to Webpack 4 will clear this issue up.
Did anyone tried with latest RC? Any performance increase?
I cant believe this is single threaded...