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.
@filipesilva yes, I am running some tests on ours now to see what the benefit is in our scenario.
So if my understanding is correct, before, uglify was never run on the vendor libraries (probably because we could assume they were already minified/optimized) and now that the vendor chunk is by default disabled, the optimizer now runs over all of the third-party libraries as well?
Where is the reduction in code size coming from? Tree shaking?
@elesueur uglify is ran over all bundles, vendor or otherwise. The size reduction comes from some advanced optimizations in Build Optimizer.
See https://github.com/angular/devkit/tree/master/packages/angular_devkit/build_optimizer for more information. There's also a talk about it (https://www.youtube.com/watch?v=usRrkAzZ108) that goes into a bit more detail on what's happening.
We also have some more improvements to production build speed in 1.7, which you can try today via @angular/[email protected].
Thanks @filipesilva is there any analysis of the build speed or is build speed basically ignored because it's considered a one-time payment for a long-time benefit?
Here is analysis of our app. The build is of course single threaded so my macbook's dual core processor is only half utilized. The system was mostly idle otherwise. I am running a second datapoint because this morning my first attempt at the 1.6 build was taking much longer than 18 minutes under similar conditions. But long story short, a much longer build for a 2% reduction in code size.
====
After (cli 1.6 with default optimizations and AOT):
Date: 2018-01-19T15:38:57.874Z Hash: f0ff32f352d583d9a60e Time: 1064637ms (18 mins) chunk {scripts} scripts.a09df21daa6632eb9407.bundle.js (scripts) 33.3 kB [initial] [rendered] chunk {0} 0.d021fc4a7108538dfdf5.chunk.js () 89.3 kB [rendered] chunk {1} main.b3bf84b1941b7f2c01c2.bundle.js (main) 4.42 MB [initial] [rendered] chunk {2} polyfills.50f916ca991d321c737c.bundle.js (polyfills) 624 kB [initial] [rendered] chunk {3} styles.ed292a274fc61d960e6a.bundle.css (styles) 422 kB [initial] [rendered] chunk {4} inline.c14b5104142c89623613.bundle.js (inline) 1.47 kB [entry] [rendered]
vendor + main = 4.42MB
Before (cli 1.4 with default optimizations and AOT)
Date: 2018-01-19T15:02:38.152Z Hash: 1be9e9d293dabdb3ca0d Time: 285541ms (5 mins) chunk {scripts} scripts.a09df21daa6632eb9407.bundle.js (scripts) 33.3 kB [initial] [rendered] chunk {0} 0.d021fc4a7108538dfdf5.chunk.js () 89.3 kB [rendered] chunk {1} polyfills.5b6fa84cc1992d5fb122.bundle.js (polyfills) 624 kB [initial] [rendered] chunk {2} main.9f0ad465d9688fbae36f.bundle.js (main) 1.59 MB [initial] [rendered] chunk {3} styles.ed292a274fc61d960e6a.bundle.css (styles) 422 kB [initial] [rendered] chunk {4} vendor.0d5ee7b13af3505dfd6a.bundle.js (vendor) 2.94 MB [initial] [rendered] chunk {5} inline.7abf96772a9fd0fe6c28.bundle.js (inline) 1.47 kB [entry] [rendered]
vendor + main = 4.53MB
Difference in time is +13 minutes Difference in size is -110KB
Thanks for the analysis @elesueur, seeing concrete numbers always helps.
My example was Angular.io, where Build optimizer reduced the bundle from ~1200kb to ~600kb. Re-enabling the vendor chunk there made it to up to 850kb. Size reduction varies with projects and is usually bigger the more core angular packages (including material) are used.
I'm looking at using cache and parallelization for Build Optimizer in https://github.com/angular/angular-cli/pull/9295, which should help reduce the build time. @clydin was also looking at a some lightweight transformations in https://github.com/angular/devkit/pull/346.
@elesueur if you have some time, could you also try with 1.7.0-beta.1?
@clydin does 1.7.0-beta.1 include the changes from @filipesilva's PR9295?
@clydin with 1.7.0-beta.1 I get a much better time:
Date: 2018-01-19T16:42:19.664Z Hash: 2591b618214eda399bdc Time: 303353ms chunk {scripts} scripts.a09df21daa6632eb9407.bundle.js (scripts) 33.3 kB [initial] [rendered] chunk {0} 0.83ab10e09bad63e047f5.chunk.js () 89.9 kB [rendered] chunk {1} main.4531b31adb9a517a8685.bundle.js (main) 4.44 MB [initial] [rendered] chunk {2} polyfills.50f916ca991d321c737c.bundle.js (polyfills) 624 kB [initial] [rendered] chunk {3} styles.cfdfe4999edebddcfc3c.bundle.css (styles) 419 kB [initial] [rendered] chunk {4} inline.5c99c209a7f19ff42247.bundle.js (inline) 1.47 kB [entry] [rendered
and pretty close to the same optimization.
@elesueur the current beta does not contain PR9295. It does contain several other performance optimizations.
Very very slow here also, went from 7min to 42+ minutes.
Using @angular/[email protected] and also --build-optimizer=false.
NODE_OPTIONS="--max-old-space-size=8192" ng build --aot --sourcemaps=true --build-optimizer=false --app 0 --locale es --environment=prod --vendor-chunk=true
Using @angular/[email protected] and [email protected] our build time looks normal again (aot+build optimizer enabled).
Before beta.2 (~50mins)
Hash: 02f1a2706d3f429e32ef
Time: 3121335ms
chunk {0} 0.619b0351c23f5dbface9.chunk.js, 0.619b0351c23f5dbface9.chunk.js.map () 5.41 kB [rendered]
chunk {1} main.4fa6a69c9838325ec97a.bundle.js, main.4fa6a69c9838325ec97a.bundle.js.map (main) 3.17 MB [initial] [rendered]
chunk {2} polyfills.0d84dd3ba77448d5366c.bundle.js, polyfills.0d84dd3ba77448d5366c.bundle.js.map (polyfills) 221 kB [initial] [rendered]
chunk {3} styles.95a5f4de371f4c77165d.bundle.css, styles.95a5f4de371f4c77165d.bundle.css.map (styles) 69.7 kB [initial] [rendered]
chunk {4} inline.54fc964e24b358bc47f3.bundle.js, inline.54fc964e24b358bc47f3.bundle.js.map (inline) 1.53 kB [entry] [rendered]
After beta.2 (~8mins)
Hash: 91fd480e9565d349ed95
Time: 467219ms
chunk {0} 0.b6c0ee08b80c9db0da44.chunk.js, 0.b6c0ee08b80c9db0da44.chunk.js.map () 5.46 kB [rendered]
chunk {1} main.67232ef58178f54910ed.bundle.js, main.67232ef58178f54910ed.bundle.js.map (main) 3.4 MB [initial] [rendered]
chunk {2} polyfills.9bc55f47faa8d39d6cf2.bundle.js, polyfills.9bc55f47faa8d39d6cf2.bundle.js.map (polyfills) 222 kB [initial] [rendered]
chunk {3} styles.8195fa9e0bc62be2904e.bundle.css, styles.8195fa9e0bc62be2904e.bundle.css.map (styles) 59.8 kB [initial] [rendered]
chunk {4} inline.c7905c25db038b259ddd.bundle.js, inline.c7905c25db038b259ddd.bundle.js.map (inline) 1.53 kB [entry] [rendered]
Great job! Thanks @filipesilva
great @anthanh @filipesilva ! Thanks :robot: :rocket:
@angular/[email protected] includes a bunch of production perf optimizations:
- https://github.com/angular/devkit/pull/346
- https://github.com/angular/angular-cli/pull/8668
- https://github.com/angular/angular-cli/pull/9295
We hope these will improve production build times overall.
Just installed 1.7.0-beta.3 and my build times are so much better! These improvements were super valuable to me! Thanks so much!
Confirm 1.7.0-beta.3 is very good. 50 mins reduce to 5 mins
Can confirm migrating angular-cli from 1.6.6 to 1.7.0-rc.0 resulted in a prod build reduction from 25 minutes to 3 minutes.
Awesome, 1.6.6=>1.7.0-rc.0 reduces my production build time from 18mn to 3mn!
Edit: here is the command I use to build:
ng build --prod --environment=deploy --vendor-chunk=true --locale=fr --progress=false
Can you please write, which build command you use/which configuration for this time improvement? For me, even with 1.7.0-rc.0 build times still are almost the same, but maybe I'm doing something wrong...
@dprandzioch I posted my comand line above.
Just to be sure, did you install 1.7.0-rc.0 locally (local version has priority over global one)?
npm i --save-dev @anguler/[email protected]
ng --version