Repository navigation
Build with "ng -prod" is extremely slow #6795
Description
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.
Activity
ankeshdave commentedon Jun 25, 2017
@filipesilva Is this the expected behavior, do i need to change something ?
filipesilva commentedon Jun 27, 2017
Production builds are usually slower than development builds. Besides using
--aot, other optimizations are also used.I do think your build time is too long though. I haven't seen other apps that have such a big difference between prod and dev build time.
chunk asset optimizationis a phase where sourcemaps are usually handled... but you have them turned off.I'm unsure of what's happening. Perhaps it's related to webpack/webpack#4863.
Is this a public project that I can look at? You might also have a cyclic dependency perhaps.. if so, #6813 could help you.
Note: sourcemaps are disabled in production builds by default, while css extraction is enabled by default.
elvisbegovic commentedon Jun 28, 2017
Same problem here
ng build --aot=false: 41286msng build --aot=false --prod: 66594msng build --prod: 193155ms@filipesilva you can check here if you can see import problem : https://plnkr.co/edit/xMf8HXoNIhq3urJ6cPXQ?p=preview
This is one proble "slow" but Other problem is : I don't understand why on dev mode "ng serve" after cli recompile fils changes and finish the browser autorefresh and I need wait 6-7seconds until browser finish refreshing this is very very big and make me crazy
GoNode5 commentedon Jun 29, 2017
@filipesilva how is Angular-cli tested with real life projects? 20-50 modules and 5-10 thirdpary JS Libs?
hoangit21 commentedon Sep 21, 2017
Same issue here. Im using
@angular/cli: 1.4.2
node: 8.5.0
Os: Mac os sierra.
Script: ng build --prod --env=prod
billdwhite commentedon Sep 27, 2017
Same issue here:
@angular/cli: 1.4.3
node: 8.5.0
OS: Mac OSX 10.13 (High Sierra)
ng build --prod --env=prod --target=production --sourcemaps
billdwhite commentedon Sep 28, 2017
FYI, it speeds up considerably when I leave off the --sourcemaps option. Off course, that's a must have so it still needs a fix......
ShadowManu commentedon Oct 28, 2017
Anything on this @filipesilva? We are running
ng build --prod --aotand having times of:mko commentedon Nov 9, 2017
Any update on this? We're even to the point where we're seeing JavaScript heap errors when we compile with sourcemaps turned on.
thatisuday commentedon Nov 17, 2017
Angular CLI: 1.5.2
Node: 7.10.0
OS: win32 x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.2
@angular/material: 5.0.0-rc0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.2
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1
gozeon commentedon Nov 23, 2017
KissBalazs commentedon Nov 30, 2017
Angular 5
Time: 413322ms
chunk {0} polyfills.1970941146babc162eea.bundle.js (polyfills) 99.8 kB [initial] [rendered]
chunk {1} main.14b317fb1264dafeb9ad.bundle.js (main) 3.96 MB [initial] [rendered]
chunk {2} styles.1d741fb54f277aec9a5f.bundle.css (styles) 738 bytes [initial] [rendered]
chunk {3} inline.51acfa358278247dad6c.bundle.js (inline) 1.45 kB [entry] [rendered]
143 remaining items
hahn-kev commentedon Dec 1, 2018
@HarelM Yeah I did build it with
--prodbut this is a nice desktop, so definitely faster then what you get from appveyor.Oh ok, yeah I didn't build the openlayers branch. But I had really slow build times when using source maps when I had scss and css. But it doesn't look like you have source maps on, so maybe you're hitting a different issue?
HarelM commentedon Dec 1, 2018
I now see that the debug builds when using the
--watchflag in angular 7 are now significantly slower (about 10-15 seconds instead of 2-3). I'm considering downgrading back to 6... :-(HarelM commentedon Dec 3, 2018
TL;DR: use
increase-memory-limitpackage.After a long trial and error I got to this issue: #5618 which started to happen on my builds.
I'll post a nice solution in the issue above, but apparently allowing node to have more memory reduces the build time significantly - build that was taking 43 minutes now finishes in about 5 minutes! :-)))
Hope this will help others as well.
jamesona commentedon Dec 4, 2018
@thenslerse, sorry to necro-tag you here, but were you by chance using semantic-ui in this project? I get the exact same two warnings in my app.
muthufmass commentedon Dec 10, 2018
angular universal is too slow to build, takes more than 20-30 mins to build and its not smooth to build and release. cant it be simplified ? I do the client build , then it does a server build, then again it will do a webpack to package a server.js which goes with all plugins that we add up , close to 24-30 mb single file. definitely needs a simplified way or fast build flow.
yeahrow commentedon Dec 14, 2018
@Brandon-Born Thank you!!!
skylarmb commentedon Dec 17, 2018
I cannot even compile a small boilerplate-based project (angular-material, a 2-3 dozen very small modules, <5k LoC total) on a 1gb ram EC2 instance, even with every possible memory intensive option disabled:
Even with all these flags disabled, on my local machine this takes about 1.2gb of ram and about 30 second to build on an i7 based machine. Unacceptable.
alberto-chiesa commentedon Dec 21, 2018
@skylarmb Unacceptable by who? Depending upon which absolute standard? The build of Javascript applications is complex. 1GB RAM is absolutely nothing. You should expect to have build occupy a lot of resources. The issue is time, not RAM usage. 30 seconds to build, considering you are starting at least 4 processors (tsc, sass, the whole npm thing, Uglify, WebPack, and who knows what else), is perfectly acceptable if there is a way to keep the development build shorter (which usually is the case).
With JS, you are exchanging resources for flexibility and convenience.
If you want to use less RAM, use GoLang. ;)
inthegarage commentedon Dec 21, 2018
@alberto-chiesa (trolling accepted :-)) Whilst there are no real benchmarks for such processing from the angular team, we can clearly see severe regression whilst compiling. An angular 7 project with a similar amount of files to a Angular 5 one takes 5x as long here on our development environments. It should also be noted that this is after memory and other optimizations, without those it was taking nearly 8x as long. We've gone backwards here.
Both Jenkins boxes have similar capabilities and enough resources for a standard compile.
Angular 7 is very slow in its compilation times, there's enough evidence on this post alone for that.
The unacceptable part is that development teams are being held up, boxes overloaded and it looks generally inefficient.
A couple of files as the poster suggests should take no longer than the Sass build, which for us is around 5s. Casting my mind back over the years of compilation, I don't think we are being unreasonable with our demands here.
alberto-chiesa commentedon Dec 21, 2018
@inthegarage I'm not saying that there are no problems. I'm following this thread from the very beginning. I'm just saying that considering unacceptable that the Angular build requires more than 1 GB of RAM is naive. The issue is time: if the build is 5x slower, it's a problem (a huge one). But, if I can get the same build time throwing in more RAM, it becomes less of a problem.
Again, I don't want to troll anyone, and I'm well aware of long build times, but the build hardware target can't be "a 1gb ram EC2 instance". If you say: "build time is too slow", I'm 100% with you.
If you say "build takes too much RAM", I can just say "it would be nicer if it took less, but I really don't care that much".
I hope I have clarified this point. No trolling intended :)
inthegarage commentedon Dec 21, 2018
@alberto-chiesa Agreed, there are some naive assumptions and when an IDE can gamefully hog 3GB+, to expect a compiler to use anything less is not realistic. All points clarified.
I also wish there was more urgency and activity with this problem. We seem to be in a "Jam tomorrow" situation. 1st it was wait for terser, second it was try angular 7, then mess about with some settings. Nothing has reduced the build times correctly and that's very frustrating.
rafa-suagu commentedon Dec 23, 2018
Hi all,
After upgrade all the dependencies our compilations times are significantly increased, from ~2min to more than 25min (we have not waited so long).
Checking which dependency have the problem, we found the last version of Terser. We solve the problem fixing it to the 3.8.1.
filipesilva commentedon Dec 27, 2018
Hey all,
There were two performance regressions recently that affected 7.x.
The first was in CLI 7.0 was affected by #12646, fixed by angular/angular#26734 and microsoft/TypeScript#28028.
Using at least
typescript@3.1.6,@angular/core@7.0.2and `@angular-devkit/build-angular@0.10.7 as per #12646 (comment) should take care of it.CLI 7.1 was affected by #13102, which will be fixed by #13309, and should be out in next patch versions of the CLI build system (
@angular-devkit/build-angular@0.11.5).I think that in the past having this single issue for all performance related problems was useful, but it's not as useful anymore. More than a year has passed with a lot of new versions of Angular CLI in between then and now.
During that time a number of performance regressions came up, were fixed, and new ones came up. Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed.
At the time of writing this comment, there are 116 hidden comments:
Having so many hidden comments makes it hard for people to find information in anything but the latest comments. But on the other hand I don't think most people would go through all of the comments anyway. New users that see this thread mostly read the first and latest comments and lose things said in between.
So instead of having this mega-issue, we'll try to have current high impact performance issues pinned at the top of the issue tracker:
Generally speaking, if you are using the latest version of the CLI build system (that's
@angular-devkit/build-angularand should be on yourpackage.json) and notice a performance problem, please check the pinned issues. If you don't see anything performance related there, please open a new one.Another thing to keep in mind is memory usage, which has a similar issue in #5618. Bigger projects take more memory to build, and when you are close to the memory limit performance may suffer. Please bear in mind that project size is not only your source code, but also includes all of the libraries you use.
Please check my comment in #5618 (comment) to see how you can increase the memory limit.
So for the reasons stated above (high volume of comments, hidden comments, hard to report and inform people) I'm also locking this issue to prevent this comment from being lost as new comments come in.
Thank you to everyone that reported and helped diagnose these performance problem. If you encounter any new ones, please open a new issue so we can give that specific regression our full attention and provide a resolution for it.