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

We had a particularly nasty regression with 7.0 listed as https://github.com/angular/angular-cli/issues/12646. The main problem there should be fixed by using @angular/core@~7.0.2 and [email protected].

@negberts not sure what's happening in your project really. Is it open source, or somewhere I could look at?

filipesilva avatar Nov 09 '18 10:11 filipesilva

Isn't AOT supposed to minimize the size by excluding what is not being used

nope, aot is about pre-compiling your templates and boosting up app/modules startup by removing runtime compiler and runtime compilation phase

artaommahe avatar Nov 09 '18 11:11 artaommahe

@artaommahe that's probably what I meant. ;-) But to be honest, I have the experience that the --aot=false version is actually starting up faster.. Not very strange I think if you compare the total size of the bundles…

@filipesilva unfortunately it is not :-( But all packages are up-to-date. I've attached the build outcomes. You need anything else? Angular.json? Package.json?

ngbuildcompare.xlsx

negberts avatar Nov 09 '18 12:11 negberts

@negberts aot precompiles the HTML templates into straight forward js files which keep the view updated. These are larger than the templates themselves, so there's a point where the combined size surpasses the size of the runtime compiler. It saves time at runtime because it's a step done in advance.

But you pointed out the bundles are so much bigger you consider the non-aot is faster to startup. Which may be true for uncached assets, plus the difference in parsing a larger file. I build into a single bundle, so your experience with so many bundles ought to be different.

I suggest you compare these options on different devices as well. Mobile and desktop, and keep the one that perform better.

awerlang avatar Nov 09 '18 14:11 awerlang

Since recent versions I can't use appveyor CI no more since the build runs more than an hour. I've updated to latest version (from 6 to 7) hoping it would improve but it just got worse. I've tried to use build-optimizer=false but the build fails (What??). I'd love for some insights, I'm desperate... Code can be found here: https://github.com/IsraelHikingMap/Site Appveyour build can be found here: https://ci.appveyor.com/project/IsraelHikingHost/site The relevant branch which I'm currently working on is called openlayers. Please let me know if you need anything else. Production build used to run for about 10 minutes in angular version 4-5 I think... I've sent a heart breaking mail to appveyor and asked them to increase the timeout, hope they would help out, but I would really like my build to take less time, this is not a huge app...

HarelM avatar Nov 30 '18 21:11 HarelM

@HarelM 2 things you could try that seemed to help me. Upgrade @angular-devkit/build-angular you're on version 8, but version 10 is out (not sure why this isn't updated when you update the cli or anything else)

You're also mixing scss and css. Which doesn't seem like it would be a big deal, but when I converted all my css files over to scss, I saw my build time drop quite a bit.

I just tried it out on your repo and didn't see much change, but the build only took a little over a minute for me.

hahn-kev avatar Dec 01 '18 02:12 hahn-kev

@hahn-kev Thanks for the super quick response! As can be seen here on the openlayers branch the devkit version is 0.11: https://github.com/IsraelHikingMap/Site/blob/dd78814bc11b86fc66157943e79e3a3d8e85488d/IsraelHiking.Web/package.json#L60 I'll try to migrate all my css file to scss, although I have a generated one from icomoon which I don't fancy migrating every time I change it, but if it will reduce the build time I'll give it a go.

but the build only took a little over a minute for me.

Did you build it with --prod? In any case, the appveyor servers are limited on resources and it is taking a very long time there. They were kind enough to extend the timeout to 90 minutes just now, I hope it will be enough...

HarelM avatar Dec 01 '18 07:12 HarelM

@HarelM Yeah I did build it with --prod but 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?

hahn-kev avatar Dec 01 '18 08:12 hahn-kev

I now see that the debug builds when using the --watch flag in angular 7 are now significantly slower (about 10-15 seconds instead of 2-3). I'm considering downgrading back to 6... :-(

HarelM avatar Dec 01 '18 21:12 HarelM

TL;DR: use increase-memory-limit package. 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.

HarelM avatar Dec 03 '18 21:12 HarelM

@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.

WARNING in Invalid background value at 147:97. Ignoring.
WARNING in Invalid background value at 171:56164. Ignoring.

jamesona avatar Dec 04 '18 19:12 jamesona

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.

muthufmass avatar Dec 10 '18 07:12 muthufmass

@Brandon-Born Thank you!!!

yeahrow avatar Dec 14 '18 11:12 yeahrow

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:

"optimization": false,
"outputHashing": "all",
"sourceMap": false,
"extractCss": false,
"namedChunks": false,
"aot": false,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": false

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.

skylarmb avatar Dec 17 '18 23:12 skylarmb

@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. ;)

alberto-chiesa avatar Dec 21 '18 11:12 alberto-chiesa

@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.

inthegarage avatar Dec 21 '18 14:12 inthegarage

@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 :)

alberto-chiesa avatar Dec 21 '18 14:12 alberto-chiesa

@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.

inthegarage avatar Dec 21 '18 16:12 inthegarage

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.

rafa-suagu avatar Dec 23 '18 12:12 rafa-suagu

Hey all,

There were two performance regressions recently that affected 7.x.

The first was in CLI 7.0 was affected by https://github.com/angular/angular-cli/issues/12646, fixed by https://github.com/angular/angular/pull/26734 and https://github.com/Microsoft/TypeScript/pull/28028.

Using at least [email protected], @angular/[email protected] and `@angular-devkit/[email protected] as per https://github.com/angular/angular-cli/issues/12646#issuecomment-435189691 should take care of it.

CLI 7.1 was affected by https://github.com/angular/angular-cli/issues/13102, which will be fixed by https://github.com/angular/angular-cli/pull/13309, and should be out in next patch versions of the CLI build system (@angular-devkit/[email protected]).

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:

image

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:

image

Generally speaking, if you are using the latest version of the CLI build system (that's @angular-devkit/build-angular and should be on your package.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 https://github.com/angular/angular-cli/issues/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 https://github.com/angular/angular-cli/issues/5618#issuecomment-450151214 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.

filipesilva avatar Dec 27 '18 13:12 filipesilva