angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Build with "ng -prod" is extremely slow

Open ankeshdave opened this issue 9 years ago • 160 comments

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.

ankeshdave avatar Jun 24 '17 04:06 ankeshdave

1.7.0-rc.0 is much faster for me as well, but for some reason my fonts are not loaded correctly. It seems like the browser loads all versions (eot, svg, ttf, woff, woff2), and non of them are "active".

remisture avatar Feb 15 '18 09:02 remisture

@remisture This has already been fixed but you'll need to wait for a new release

PascalTemel avatar Feb 15 '18 09:02 PascalTemel

@Toub @remisture @PascalTemel reasons for theses improvments are because build currently ignore fonts this decrease build time dramatically, when this enabled again it will still be slow and block at 92% ... (joke)

I don't know how you guys have theses improvments, seems not applied to me, ps: TBH i don't care a little bit about build time, important to me is serve with aot in big project (>1k files), that is also improved to you ? first build ng s --aot : 90959ms rebuild ng s --aot : 27115ms rerebuild ng s --aot : 23896ms rererebuild ng s --aot : 0% blocking crashed

elvisbegovic avatar Feb 15 '18 12:02 elvisbegovic

1.6.6 (ng build --prod --aot) Time: 2552417ms (42 min) chunk {scripts} scripts.2f2e0b85b06251853901.bundle.js (scripts) 338 kB [initial] [rendered] chunk {0} main.1090a59971a754842795.bundle.js (main) 6.73 MB [initial] [rendered] chunk {1} polyfills.8477fbb8c7fe3ad47cff.bundle.js (polyfills) 64.1 kB [initial] [rendered] chunk {2} styles.ebeede0f32b58cd49beb.bundle.css (styles) 529 kB [initial] [rendered] chunk {3} inline.a8a43773191a9152089a.bundle.js (inline) 1.45 kB [entry] [rendered] (~7,6MB)

1.7.0 (ng build --prod --aot) Time: 139403ms (2 min) chunk {scripts} scripts.2f2e0b85b06251853901.bundle.js (scripts) 338 kB [initial] [rendered] chunk {0} main.7855996d44fe44035a13.bundle.js (main) 3.23 MB [initial] [rendered] chunk {1} polyfills.e412e915007454c18396.bundle.js (polyfills) 64.1 kB [initial] [rendered] chunk {2} styles.a13a24dba7f782b93952.bundle.css (styles) 522 kB [initial] [rendered] chunk {3} inline.318b50c57b4eba3d437b.bundle.js (inline) 796 bytes [entry] [rendered] (~4,1MB)

Great! Thank you!

eddie-kann avatar Feb 21 '18 04:02 eddie-kann

Our large project is now ~2.35x Faster at building for aot/prod - THANK YOU

Here's our measurements for Angular-CLI 1.6.4 (11.4min / 53MB) vs 1.7.1 (4.8min / 53MB):

Number of files under src/:
   5 DS_Store
   1 eot
   1 gif
   1 gitkeep
 146 html
  38 jpg
   2 json
   1 md
   1 npmignore
   4 otf
  52 png
 149 scss
  16 svg
 319 ts
   1 ttf
   1 woff
Angular CLI: 1.6.4
Node: 7.5.0
OS: darwin x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.4
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.4
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0

==================================
[AOT & PROD]  (timing)
   node --max_old_space_size=16192 node_modules/.bin/ng build -aot -prod -pr false -op timing-aot-prod

Execution time was 689 s (11 m)

Size of build:
3.1M	timing-aot-prod/assets
4.0K	timing-aot-prod/inline.a70b262748fe0a55d310.bundle.js
 22M	timing-aot-prod/main.34955e8e2b71226ac437.bundle.js
224K	timing-aot-prod/polyfills.769e09b99ce9001df0b0.bundle.js
296K	timing-aot-prod/scripts.bcd65afe20c96c2e4da3.bundle.js
2.3M	timing-aot-prod/0.dd629e968ecf01ac6841.chunk.js
5.6M	timing-aot-prod/1.578685531c3f1f4e6954.chunk.js
1.2M	timing-aot-prod/2.39c050c69186a24a8177.chunk.js
1.4M	timing-aot-prod/3.dce8ef7db7a4e2a16c35.chunk.js
 11M	timing-aot-prod/4.442f379ca140db46fc06.chunk.js
1.3M	timing-aot-prod/5.4c49e82c71452ff05580.chunk.js
4.6M	timing-aot-prod/6.cb7659914c4345fda23a.chunk.js
 32K	timing-aot-prod/index.html

Total size
53M    timing-aot-prod
Angular CLI: 1.7.1
Node: 7.5.0
OS: darwin x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.1
@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

==================================
[AOT & PROD]  (timing)
   node --max_old_space_size=16192 node_modules/.bin/ng build -aot -prod -pr false -op timing-aot-prod

Execution time was 293 s (4 m)

Size of build:
3.1M	timing-aot-prod/assets
4.0K	timing-aot-prod/inline.cd131d510872097ecdeb.bundle.js
 22M	timing-aot-prod/main.f9fe7d98f354f3c411b7.bundle.js
224K	timing-aot-prod/polyfills.9cbf815124d5a3f9dcf2.bundle.js
296K	timing-aot-prod/scripts.bcd65afe20c96c2e4da3.bundle.js
2.3M	timing-aot-prod/0.2dc8a55cddfff64c6380.chunk.js
5.5M	timing-aot-prod/1.fffa7fd0f0133cc15cae.chunk.js
1.2M	timing-aot-prod/2.fecff394c1eb0cafd4f7.chunk.js
1.4M	timing-aot-prod/3.700d00e7c952fd0312d9.chunk.js
 11M	timing-aot-prod/4.278f5a8e5f8aa887b533.chunk.js
1.3M	timing-aot-prod/5.140fbfc2a6af6609ae13.chunk.js
4.6M	timing-aot-prod/6.f3fd2e34889dca730e53.chunk.js
 32K	timing-aot-prod/index.html

Total Size of build:
 53M    timing-aot-prod

subatomicglue avatar Feb 22 '18 19:02 subatomicglue

Happy to hear that 1.7.0 is helping keep prod build time manageable! We put in a lot of prod optimizations in 1.7.0.

I'll leave this issue open for a few more weeks to see if there's anything off with our fixes.

filipesilva avatar Feb 23 '18 08:02 filipesilva

I can confirm that now we build with optimizations in almost the same time as before (1.6.x), but with --build-optimizer=false.

Please, keep an eye on this subject, because build times are now acceptable, but "fast" is quite another thing.

Anyway, your work is so invaluable that no "thanks" is enough! And really, really appreciated. IMO, we just need to be more stable, predictable, fast (at both build and runtime) and slim. New features can come later.

alberto-chiesa avatar Feb 23 '18 09:02 alberto-chiesa

This issue doesn't affect me now in the size of the projects I'm working on, but I wanted to make a little stop to give my token of appreciation to @filipesilva and all the angular cli team and contributors that work hard and try to solve the community problems.

With all the desire to put a smile on your faces: you guys rock!

ShadowManu avatar Feb 23 '18 15:02 ShadowManu

😄

filipesilva avatar Feb 23 '18 15:02 filipesilva

So, I realized I did my testing with 1.7.1 but the discussion above is with 1.7.0... Would performance be better with 1.7.0 instead? 5min build is faster than 11min, but not really 10x improvement either, so I was wondering

Looks like 1.7.1 is released: https://github.com/angular/angular-cli/releases

subatomicglue avatar Feb 23 '18 16:02 subatomicglue

@subatomicglue it should be the same really. I don't think anything important changed between those to as far as build speed is concerned.

filipesilva avatar Feb 23 '18 16:02 filipesilva

Guys, I am using 1.7.1 and struck with 92% from half-n-hour. Disabling source-map and build-optimizer is workaround but not a solution. Please provide with better solution for the issue

bharathmuppa avatar Feb 27 '18 15:02 bharathmuppa

Are you sure you are on 1.7.1 also in node_modules local folder? If you do ng --version what do you read? Chances are you have 1.7.1 in global only.

alberto-chiesa avatar Feb 27 '18 15:02 alberto-chiesa

I'm on 1.7.2 and when running ng build --prod --sourcemaps=true --target=production I'm getting stuck on 95% emitting for 30+ minutes both locally (and on the CI server). Works fine on 1.6.8. What I have is a pretty small Angular application. Just letting you know in case you have the solution. More than happy to provide more details if you need them. Cheers.

todthomson avatar Mar 01 '18 09:03 todthomson

@todthomson is this app something we could look at? Small apps exhibiting this sort of behaviour point towards some hard to find performance bugs.

filipesilva avatar Mar 01 '18 10:03 filipesilva

@filipesilva I can't provide source (sorry) as it's a project I'm doing on behalf of one of our clients, but I may be able to do a screen share if that would work for you? Please confirm and I'll try to get approval from the client. Cheers. 💯

todthomson avatar Mar 01 '18 21:03 todthomson

@todthomson could you take a CPU profile perhaps? I have some instructions in https://github.com/angular/angular-cli/issues/8259 that you could use.

filipesilva avatar Mar 01 '18 22:03 filipesilva

I've just upgraded my CLI to 1.7.2 (I've double checked the node_modules and --version) and a my build time has gone from about 15 seconds to infinity It hangs forever at "92% chunk asset optimization", I've waited more than 10 mins before giving up

It's a very small app

benc-uk avatar Mar 02 '18 16:03 benc-uk

@benc-uk is this app something you could share so we can debug?

filipesilva avatar Mar 02 '18 16:03 filipesilva

OK now I look stupid, it's working! I did a ng build --prod --build-optimizer=false which ran OK, and since then a regular ng build --prod runs in about 12 seconds again

benc-uk avatar Mar 02 '18 17:03 benc-uk