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

Rebuild extremely slow

Open asadsahi opened this issue 10 years ago • 226 comments

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Windows 10

  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.11-webpack.8 node: 6.3.0 os: win32 x64

  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. app created with 1.0.0-beta.11-webpack.2 and later on upgraded to 1.0.0-beta.11-webpack.8 with appropriate changes.

  4. The log given by the failure. Normally this include a stack trace and some more information. The slow behavious is observed when upgraded from 1.0.0-beta.11-webpack.2 to 1.0.0-beta.11-webpack.8

  5. Mention any other details that might be useful. Slow behavious reproduceable in following repo: https://github.com/asadsahi/ng2fb-bootstrap


I have experience this on two operating systems, windows 7 and windows 10. Has anyone else experieced this? For me rebuilds are dramatically slow, taking roughly 7-8 seconds which on same machine with cli version webpack.2 was taking rougly 2-3 seconds.

asadsahi avatar Sep 05 '16 10:09 asadsahi

@filipesilva ng -v on my window 10 machine takes around 25-26 seconds to display version no.

With HMR, First load takes ~30 secconds and rebuild time on same machine 12-13 seconds.

machine spec: image

Actually, this is the time I see in console, but my estimates are from rebuild start to browser readly after reload:

image

asadsahi avatar Dec 21 '16 22:12 asadsahi

@simonech @asadsahi can you do me a favor and try this to see build time?

git clone https://github.com/filipesilva/angular-cli-benchmark-app
cd angular-cli-benchmark-app
npm install
npm start

Then copying ./src/ onto a ng new project and see the ng build time there as well.

My point in asking this is to see if there is a vast difference between running the webpack compilation from within the CLI or from a barebones project.

I tested this in my machine and the CLI was faster, but I begin to wonder if there is something that is slowing down other setups.

filipesilva avatar Dec 21 '16 23:12 filipesilva

@filipesilva

angular-cli-benchmark-app build times:

image

new angular-cli project build times before overriting angular-cli-benchmark-app src:

image

After overriting angular-cli-benchmark-app src > new angular-cli project:

image

asadsahi avatar Dec 22 '16 11:12 asadsahi

@asadsahi thank you for the time you took to put these together.

The missing require is relevant somewhat. Mostly because it was something that would only happen in older versions of the CLI. That together with the fact that you're not getting an auto-generated vendor bundle makes me think the generated project is actually on beta.19 or beta.20.

Can you confirm what version you used for that test please? beta.22 and above brought many improvements to the build speed. A lot of the time in your screenshot is being spent on building modules, and if I remember correctly that was an issue related to awesome-typescript-loader (which we then switched to @ngtools/webpack).

If you have the time, I would appreciate those two tests repeated with beta.24. You shouldn't need to update your global version, it should be enough to update the local project one.

filipesilva avatar Dec 22 '16 11:12 filipesilva

@filipesilva sorry, installation of beta 24 didn't happen correctly, Beta 20 stuck on windows 10 even after cleaning cache. So I have to manually delete angular-cli folders and did beta 24 install globallay and created new projects from scratch. I can confirm new tests are from beta 24.

I have updated above screenshots with new build/rebuild times. Let me know if you need any more information.

Thanks

asadsahi avatar Dec 22 '16 13:12 asadsahi

@filipesilva Did some tests with your benchmark repo on my system. The results are:

For the angular-cli-benchmark-app:

Hash: 65007cd0b108b0cabe02
Version: webpack 2.1.0-beta.25
Time: 7634ms
               Asset       Size  Chunks             Chunk Names
     0.bundle.js.map     111 kB       0  [emitted]  
         0.bundle.js     107 kB       0  [emitted]  
         2.bundle.js    2.46 kB       2  [emitted]  
      main.bundle.js    6.06 kB       3  [emitted]  main
    vendor.bundle.js     2.8 MB       4  [emitted]  vendor
         1.bundle.js     107 kB       1  [emitted]  
     1.bundle.js.map     111 kB       1  [emitted]  
     2.bundle.js.map    1.02 kB       2  [emitted]  
  main.bundle.js.map    3.67 kB       3  [emitted]  main
vendor.bundle.js.map       3 MB       4  [emitted]  vendor
          index.html  402 bytes          [emitted]  

For the angular-cli generated project:

Hash: c6e22cffdebd68f501db                                                              
Time: 8578ms
chunk    {0} 0.chunk.js, 0.bundle.map 87 kB {3} {2} {1} [rendered]
chunk    {1} 1.chunk.js, 1.bundle.map 86.9 kB {2} {0} {3} [rendered]
chunk    {2} 2.chunk.js, 2.bundle.map 1.76 kB {0} {1} {3} [rendered]
chunk    {3} main.bundle.js, main.bundle.map (main) 3.9 kB {5} [initial] [rendered]
chunk    {4} styles.bundle.css, styles.bundle.map, styles.bundle.map (styles) 1.77 kB {6} [initial] [rendered]
chunk    {5} vendor.bundle.js, vendor.bundle.map (vendor) 2.36 MB [initial] [rendered]
chunk    {6} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

My system is Ubuntu 14.04 on an i5-2450M CPU @ 2.50GHz, 8GB RAM, SSD drive

cdarken avatar Dec 22 '16 13:12 cdarken

@asadsahi awesome, thanks for the update! So your numbers clearly show an increase from 15ish secs on a webpack project to 19secs on a CLI project.

I picked the last (and best) build time for the CLI because I know it has some kind of warm up time that I think is node related. After a brand new install the first few builds are slower but then it stabilises. For instance, your numbers went from 27secs to 19secs on a operation that does not keep state (ng build).

It still is roughly 3~4 times bigger than the numbers I get. To me that says that there is a system resource being heavily stressed on your system, and that resource is being used more by the CLI than on a bare webpack config.

I will investigate on that premise. I suspect either disk access or CPU, and will see which extra webpack plugins are mostly impacting those.

filipesilva avatar Dec 22 '16 13:12 filipesilva

System Specs: i5 4460 Quad Core 16GB RAM Windows 10

My Results: Webpack Benchmark App: benchmark-app

Angular CLI Beta 24: ng-cli

rosslavery avatar Dec 22 '16 14:12 rosslavery

Guys, stop working, go home and rest and happy christmas and happy new year. 🎄 🎅 🎁

albandaft avatar Dec 22 '16 15:12 albandaft

@filipesilva I ran ng build and ng serve from a standard npm install, on a much more powerful machine (Win10 i7-3770 3.7ghz with 8GB RAM and SSD), and for both I had 8sec build time

simonech avatar Dec 22 '16 16:12 simonech

@filipesilva tested the two benchmarks

web-pack: 6529, 6311 image

ng build (using beta24 --progress=false) 6874,6786 image

I'll try it again this evening on the slower machine

simonech avatar Dec 22 '16 16:12 simonech

As raised by #3203, asset optimization seems to be still one area to check, especially when you start having a few images in assets (or, worse, in my case some binary .dll files -that's totally NOT Webpack DLLs- used for IIS auth and stuff, generated from bigger project).

It takes several seconds, and it seems to be running in partial / incremental builds (watch mode) not just initial build.

Might be possible to disable in dev?

Meligy avatar Dec 22 '16 18:12 Meligy

More data from my work machine (Poor little small form factor HP)! Specs: Windows 10 x64 Build 1607 Intel Core 2 Duo E7600 8GB Ram Samsung 850 Pro SSD

Webpack

Webpack Build Result

CLI

CLI Build Result

celliott181 avatar Dec 22 '16 19:12 celliott181

@filipesilva I ran the test again on my low-spec Microsoft Surface Pro

the webpack build was 10694, 10258 (but overall time has the usual 5 secs lag) image

Running CLI build --progress=false: 12285,11291 (with high perf power settings) image

So both on my Surface Pro and on my work machine i7, running directly webpack is slightly faster than CLI (200-300ms - 5-ish% on the fast machine, 1-1.5sec 10-ish% on the slower Surface Pro)

HTH and let me know if you want me to run other tests/benchmarks

simonech avatar Dec 23 '16 08:12 simonech

Do the assets really have to be optimised every time even if none of them have changed? A better approach would be to somehow cache the optimised assets if we need tp rebuild them every time to avoid repetition of the optimization.

RicardoVaranda avatar Dec 28 '16 12:12 RicardoVaranda

Still running pretty slow here. Rebuilds are at around 4.8s-6s, sometimes up to 9s. Our project is getting pretty large, but it still feels like the rebuild times should be much shorter, especially for .ts files. Changing a single file is most likely triggering the checking of a huge number of dependent and depended upon files instead of just transpiling that one file and then doing the checks later on.

Tried playing around with some of the webpack settings, even with adding ts-loader or awesome-typescript-loader, but couldn't get the time to go down by much. Also tried happypack (which splits the compilation into several parallel threads), but didn't succeed in making it work, probably because of webpack 2.

Anyway, any improvements here would be greatly appreciated.

UPDATE: Some more testing and it turns out I can get my rebuilt times down to around 3s-3.5s with isolatedModules and transpileOnly. Also, building the whole project with tsc takes 5.5 seconds, including checks and without isolatedModules, so it is indeed strange that with webpack and angular cli it is doing so much more stuff that it takes just as long to compile the whole project with tsc as it takes to rebuild after changing a single ts file.

hccampos avatar Dec 29 '16 20:12 hccampos

@asadsahi @cdarken @rosslavery @simonech @gelliott181 thank you so much for all the benchmarks you did! As far as I can tell the CLI is somewhat slower than a barebones webpack run, but it's usually not that much. So that really makes it seem like it's a matter of system resources. I'm looking more into making DLLPlugin work on the CLI since that seems to be the only real big performance increase in sight.

@RicardoVaranda the asset optimization listed in the verbose build is actually not related to the assets folder at all. It's related with stuff like sourcemaps, which is why that time drastically drops if you do --no-sourcemaps.

@hccampos I asked around and it turns out that happypack doesn't work with loaders that use loaderContext._compiler. This, unfortunately, is pretty much all typescript loaders.

filipesilva avatar Dec 29 '16 20:12 filipesilva

@filipesilva https://github.com/angular/angular-cli/issues/1980#issuecomment-268592049

I also need to find a way to dynamically create the list of modules that will be included in the DLL bundle since users shouldn't have to list them manually.

I think there is nothing wrong by manually listing all vendor package names in an array. I dont see any other solution how this can be automatically done. Take a look at this config file https://github.com/qdouble/angular-webpack2-starter/blob/master/constants.js#L65-L69 and on the project in general.

aegyed91 avatar Dec 30 '16 12:12 aegyed91

https://github.com/angular/angular-cli/pull/3805 should help with the initial command startup time. In my tests it was reduced by 50%, but since running from master also compiles the CLI's TS files on the fly, the reduction might be more dramatic after a release.

filipesilva avatar Dec 31 '16 14:12 filipesilva

npm ls --depth=0 --production

+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

from this you can get the polyfill and library list you include over npm

with npm postinstall hook you create the new dll build and make it automatic

also make it available over cli, ng build:dll to trigger it manually if need

aegyed91 avatar Dec 31 '16 16:12 aegyed91