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

This is a 3 week old project: Time: 379949ms Or 6+ minutes...

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.7.4
Node: 8.11.1
OS: linux x64
Angular:

> ng build --prod --base-href /ingest/ --deploy-url /ingest/ --preserve-symlinks

 10% building modules 6/6 modules 0 activeWARNING: The `text-hide()` mixin has been deprecated as of v4.1.0. It will be removed entirely in v5.
         on line 10 of node_modules/bootstrap/scss/mixins/_text-hide.scss, in mixin `text-hide`
         from line 57 of node_modules/bootstrap/scss/utilities/_text.scss
         from line 14 of node_modules/bootstrap/scss/_utilities.scss
         from line 41 of node_modules/bootstrap/scss/bootstrap.scss
         from line 1 of stdin

Date: 2018-04-26T16:12:10.883Z
Hash: a01a8f6065671dfa4f1b
Time: 379949ms
chunk {0} main.e9b908f1aa112ccae986.bundle.js (main) 2.22 MB [initial] [rendered]
chunk {1} polyfills.194f3db5c95bb635c66b.bundle.js (polyfills) 59.7 kB [initial] [rendered]
chunk {2} styles.5124363d8f33a39f555c.bundle.css (styles) 221 kB [initial] [rendered]
chunk {3} inline.02c5a2b14b98749c9aca.bundle.js (inline) 804 bytes [entry] [rendered]

rightisleft avatar Apr 26 '18 16:04 rightisleft

Thanks @clabough

ng build --prod-optimizer=false it worked for me.

dharmendrap7 avatar Apr 27 '18 13:04 dharmendrap7

@dharmendrap7 Glad to hear it. I've since started using ng build --prod -sm --build-optimizer false --aot false

It's even much faster to build and oddly it results in smaller bundle/chunk files. Might be a tad slower to bootstrap though - but not noticeably.

Just found that Firefox is really slow bootstrapping non-AOT compiled code.

clabough avatar Apr 27 '18 16:04 clabough

After upgrading to 6.0, ng build --prod --source-map is still taking 40 minutes. ng build --prod --source-map --build-optimizer false takes 8 minutes.

clabough avatar May 08 '18 18:05 clabough

https://github.com/angular/angular-cli/issues/8344#issuecomment-387558945

rightisleft avatar May 08 '18 22:05 rightisleft

  • node_modules/.bin/ng build --prod --build-optimizer false: 70s
  • node_modules/.bin/ng build --prod: 63s
  • node_modules/.bin/ng build --prod -sm --build-optimizer false --aot false: 74s
  • node_modules/.bin/ng build --prod --sourcemaps false --build-optimizer false --aot false: 28s :ok_hand:
  • node_modules/.bin/ng build --prod --sourcemaps false: 60s

Any better config for a fast build? I will only try check if all code its OK, on CI., for example disable chunk assets, I don't see any option for that.

Of course building modules and chunk assets processing takes a lot of time.

pablorsk avatar May 30 '18 11:05 pablorsk

Have you tried disabling source maps? In my experiments it made a lot of difference.

alberto-chiesa avatar May 30 '18 13:05 alberto-chiesa

I just updated the CLI version from 1.5.4 to 1.7.4 and the build time went down from more than 30min to less than 5min! And I didn´t deactivate the build optimizer (ng build -prod)

Angular CLI: 1.7.4
Node: 8.11.1
OS: win32 x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.7.4
@angular/language-service: 4.4.6
@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.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.6.2
webpack: 3.11.0

ampeixoto avatar Jun 08 '18 12:06 ampeixoto

Just upgraded to Angular 6 and also having problems with 'optimization: true' in our production build. Not only is the build slow (699865ms), but the app no longer works with build optimization set to true. We use Microsoft Authentication Library for Js and suddenly get mysterious "B2cAuthorityUriInvalidPath" errors from said library. Setting 'optimization: false' actually made the build take longer (769290ms) but the app now works. In both cases, I have aot set to true and sourcemaps set to true.

Angular CLI: 6.0.7
Node: 8.11.1
OS: win32 x64
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------

@angular-devkit/architect: 0.6.5
@angular-devkit/build-angular: 0.6.5
@angular-devkit/build-optimizer: 0.6.5
@angular-devkit/core: 0.6.5
@angular-devkit/schematics: 0.6.7
@angular/cdk: 6.2.0
@angular/cli: 6.0.7
@angular/flex-layout: 6.0.0-beta.16
@angular/material: 6.2.0
@ngtools/webpack: 6.0.5
@schematics/angular: 0.6.7
@schematics/update: 0.6.7
rxjs: 6.2.0
typescript: 2.7.2
webpack: 4.8.3

morr0350 avatar Jun 15 '18 18:06 morr0350

Folks, we've swtiched to ng6 with a hope that build will be faster because of webpack4. In reality - almost no difference, could you explain it?

andreyselitsky avatar Jun 20 '18 13:06 andreyselitsky

@andreyselitsky for me it actually seems to be marginally slower - with sourcemaps disabled it jumped from ~3min to ~3.5min and with sourcemaps enabled from ~13min to ~14min but those are average numbers and it could be caused also by something else, otherwise, as you said - definitely not the big win I hoped for because of webpack4

pgrm avatar Jun 20 '18 20:06 pgrm

We've had this issue for a long time across multiple projects - some big, some very small. It doesn't seem to be affected by the size of the project at all, and still occurs on Angular 6. Using ng build --prod takes absolutely insane amounts of time for the uglify plugin to finish.

Is there any fix for this on the roadmap without having to turn optimizations off?

LukeBillo avatar Jun 26 '18 10:06 LukeBillo

This may help someone.

All 4 of my CPU cores were running at 100% when I ran ng build --prod, which caused my laptop to throttle down from 3.7 ghz to 0.7 ghz due to high CPU temperatures, which was causing very long build times.

I ended up installing ThrottleStop and lowered my "Turbo Ratio Limits" when 3+ cores were in high use (to lower temps). Also adjusted my laptop fan profiles to increase fan speed when I had very high cpu usage.

DISCLAIMER: Be very careful with ThrottleStop, it gives you complete control of your CPU, which means you could fry your (or your companies) hardware if you don't know what your doing.

CLI: 6.0.7 OS: Windows 10 CPU: Intel I7-7820HQ MEM: 32GB

tuurbo avatar Jun 26 '18 17:06 tuurbo

For people with crazy slow build times with build -prod I’ll leave you with some advice that helped us: We were including bootstrap into every component’s scss file which was causing bootstrap to be included ~160 times in our project. Not only was the build output large (50mb or so unzipped) but the build took crazy amounts of time, 30 min. Now we are down to couple minutes and ~4MB uncompressed.

If you have doubts you can open your main bundle in a text editor and start asking yourself if you are seeing a lot of redundant stuff. Go from there. That’s what tipped us off.

subatomicglue avatar Jun 26 '18 17:06 subatomicglue

This has reached epic proportions ! Anybody seeing this slow ?. image

mvsrinivasan avatar Jul 01 '18 06:07 mvsrinivasan

Build times became a nightmare with ng6. The problem seems to be something related to source-maps generation. Which I can disable for prod builds, but for development time and debug, those are essential.

CLI: 6.0.8 OS: macOS 10.13.4 CPU: 3,1 GHz Intel Core i7 MEM: 16GB

90% of the time it's generating source-maps with the following output

92% after chunk asset optimization SourceMapDevToolPlugin main.js generate SourceMap

It's draining the developer performance dramatically and starts to become a show stopper.

I'd really love to get some update from the team here. Are you guys aware of this? Is there some investment to speed up the build times?

thorstenhans avatar Jul 03 '18 07:07 thorstenhans

this fixed the issue ng build --prod --build-optimizer true --aot true

spmsupun avatar Jul 03 '18 13:07 spmsupun

no, not really. Still seeing build times which are terrible.

thorstenhans avatar Jul 05 '18 09:07 thorstenhans

I do have an error occurring only on CI for some reason, within our E2E tests (cypress).

The error displayed is not saying much and I can't get the stacktrace.

I do have Sentry though and all the errors are reported there which is great! But... As sourcemap is not working I can let you imagine that checking an uglified source code is far from ideal.

Sentry does support sourcemaps :raised_hands: But I can't provide them as it's not even long, it's just crashing while building with sourcemaps on. On CI, but also on my machine which has 32gb of RAM and quite a good config in general.

92% after chunk asset optimization SourceMapDevToolPlugin main.3b1b07dccf0137765ba6.js generate SourceMap

#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
#
#
#FailureMessage Object: 0x7f89267de9b0Illegal instruction (core dumped)

maxime1992 avatar Jul 10 '18 12:07 maxime1992

@maxime1992 i bet its your its node v8 memory limit who sh*ts it and not your machine memory limit its a known problem with v8 actualy... its can be a real bitch when dealing large/long strings without chunking (node has a fixed string length limit afaik)

in my own opinion v8 can be a real pain handling FILES and parsing them ... cause of those limits. some refs https://futurestud.io/tutorials/node-js-increase-the-memory-limit-for-your-process https://bugs.chromium.org/p/v8/issues/detail?id=847

nirdshabo avatar Jul 14 '18 01:07 nirdshabo