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

This is from testing two fresh ng-init projects:

angular-cli: 1.0.0-beta.26
node: 7.3.0
os: win32 x64

CSS:

PS C:\dev\ng-css> npm run start

> [email protected] start C:\dev\ng-css
> ng serve

** NG Live Development Server is running on http://localhost:4200. **
Hash: 164111cf5cd94c55d065
Time: 6537ms
chunk    {0} main.bundle.js, main.bundle.map (main) 4.52 kB {2} [initial] [rendered]
chunk    {1} styles.bundle.js, styles.bundle.map (styles) 9.96 kB {3} [initial] [rendered]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 2.84 MB [initial] [rendered]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
webpack: bundle is now VALID.

=> Rebuild (change app.component.ts)
webpack: bundle is now INVALID.
Hash: 164111cf5cd94c55d065
Time: 2265ms
chunk    {0} main.bundle.js, main.bundle.map (main) 4.52 kB {2} [initial]
chunk    {1} styles.bundle.js, styles.bundle.map (styles) 9.96 kB {3} [initial]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 2.84 MB [initial]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry]
webpack: bundle is now VALID.

SCSS:

PS C:\dev\ng-scss> npm run start

> [email protected] start C:\dev\ng-scss
> ng serve

** NG Live Development Server is running on http://localhost:4200. **
Hash: 5585be96c8aac1577ee8
Time: 5230ms
chunk    {0} main.bundle.js, main.bundle.map (main) 4.53 kB {2} [initial] [rendered]
chunk    {1} styles.bundle.js, styles.bundle.map (styles) 10.1 kB {3} [initial] [rendered]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 2.84 MB [initial] [rendered]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
webpack: bundle is now VALID.

=> Rebuild (change app.component.ts)

webpack: bundle is now INVALID.
Hash: 5585be96c8aac1577ee8
Time: 1133ms
chunk    {0} main.bundle.js, main.bundle.map (main) 4.53 kB {2} [initial]
chunk    {1} styles.bundle.js, styles.bundle.map (styles) 10.1 kB {3} [initial]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 2.84 MB [initial]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry]

Rebuild times with these seem fine. For my large project, I have also tried uninstalling and re-adding angular-cli via yarn (to force transient dependency upgrade to latest version) without a change in rebuild times on windows. Note that with neither project I'm using symlinks (as far as I'm aware) nor do I have them on a deep path, they all live in C:\dev...

JohannesRudolph avatar Jan 20 '17 12:01 JohannesRudolph

@montella1507 how do you reach that conclusion? Rebuilds do not appear to stress my disk at all (<2% active time according to task manager).

JohannesRudolph avatar Jan 20 '17 12:01 JohannesRudolph

@filipesilva I think I have to retract my earlier reported OS-X 2.5s vs Windows 16s numbers for rebuild time. Turns out the Windows build had ng serve --aot=true and OS X had ng serve --aot=false which easily explains the difference. With --aot=true my mac builds at 24s, which matches the speed difference I expect between the machines based on running a full ng build --aot=true.... sorry for all the fuss.

Conclusion: I don't observe a difference between OS X and Windows build times not explained by different hardware.

JohannesRudolph avatar Jan 20 '17 12:01 JohannesRudolph

@JohannesRudolph well... because NTFS system is not optimized to work with 100 000 small files.. Try to remove node_modules folder on windows and on linux... Its like 120sec and 2sec.

I have tried to build our application on both linux and windows with same HW. Linux is 4times faster +-.

montella1507 avatar Jan 20 '17 12:01 montella1507

@JohannesRudolph glad to hear your issue was sorted! There still seems to be some windows issue that I can't put my finger on though.

@montella1507 I understand there are differences due to the file system, but for rebuilds I wouldn't expect that to matter since webpack keeps most of it in memory. I would expect a slower initial build, and maybe slower rebuilds when including a new big vendor, or even a bigger delay for the watchers to detect a change. But not a bigger rebuild itself.

@mrlund @tsm91 @montella1507 do you notice a rebuild difference between ng serve and ng build --watch? And could you show me the output of a slow rebuild using the --verbose flag?

Currently what I see is that overall rebuild performance is ok (but could be better), and that on some Windows setups performance is very bad.

So I'd like to find a way to repro the Windows scenario to fix what I assume to be a bug. We're also working on some accross-the-board optimizations in the AoT Plugin.

filipesilva avatar Jan 20 '17 15:01 filipesilva

Also for those that were looking at DLLPlugin, our attempts show that it's currently not possible to use together with lazy route detection.

filipesilva avatar Jan 20 '17 15:01 filipesilva

@filipesilva Yea, I tried adding it manually too, and failed miserably. I think a big cause of bad rebuild performance in large projects is the project structure itself. That is, whether you use barrels or not, whether you re-export things a lot, whether you have large modules, whether you add typings to all the variables, etc.

Unfortunately, though, I haven't been able to really determine what the best practices are to keep rebuild times low. One thing we try doing is adding types to most things so TS doesn't have to spend so much time inferring stuff, but with observables it is a PITA to do. So far not much has worked.

Do you guys have an idea of what those best practices are?

hccampos avatar Jan 20 '17 15:01 hccampos

@filipesilva DLLPlugin has been implemented in angular2-webpack-starter project recently using this webpack plugin. I like this idea as it is a pluggable way to add dll support. 3rd party packages are listed in that plugin as well. I have this working in one of my project too using same plugin. I have provided in the past stats of normal rebuild vs dll and performance is massive with DLL. And both projects have lazy routes there too.

Do we know what sort of challanges we are having with lazy routes?

asadsahi avatar Jan 20 '17 15:01 asadsahi

@asadsahi the starter you linked uses a different TS loader than we do here, and I think it can't give complete static analysis information.

I'll investigate further if the approach used in https://github.com/shlomiassaf/ng-router-loader could be used in the CLI.

filipesilva avatar Jan 20 '17 15:01 filipesilva

@filipesilva so downloaded the angular2-webpack-starter and quickly made our app work. Rebuilds take 1.5s-1.8s compared with 3.5s-17s in angular-cli. The initial build (after the dll had been created in another build) took 17s. That is compared with the 45s-60s for npm starting angular-cli.

hccampos avatar Jan 20 '17 16:01 hccampos

@filipesilva With an unmodified new project I'm seeing better perf, though I guess that's obvious. Considering the simplicity, not blistering, however: 16s build / 4,5s rebuild. My path is C:\Users<user>\Source\Repos\perftest, and no symlinked node modules.

mrlund avatar Jan 21 '17 09:01 mrlund

@hansl just added a massive performance increase in https://github.com/angular/angular-cli/pull/4145.

For a brand new project, times for ng serve third rebuild are 65% smaller :

// before
Average time: 1922.2
Results: 1939,1920,1983,1885,1884

// after
Average time: 679.6
Results: 660,677,692,671,698

On a medium sized project:

// before
Average time: 4224.2
Results: 4244,4255,4258,4220,4144

// after
Average time: 1559
Results: 1537,1575,1525,1557,1601

filipesilva avatar Jan 23 '17 00:01 filipesilva

This was merged to master, so should show up in next npm release in a couple of days, correct? I'd prefer not to link master unless it's important.

mrlund avatar Jan 23 '17 10:01 mrlund

@mrlund yes it will be included in the next release.

filipesilva avatar Jan 23 '17 10:01 filipesilva

I am going to close this issue as we have done pretty much everything possible on our side to reduce rebuild time in development. We're actively working with Webpack to improve performance on their side, and you should expect more as they release improvements on their side.

hansl avatar Feb 01 '17 01:02 hansl

The problem is each time you save a file webpack will re-create the whole dependency graph of all the vendor and polyfill packages. On top of it, if you are doing this on an ntfs filesystem (windows) it will further increase the rebuild time.

I really wonder why you guys didn't implement webpack.DllPlugin. Last week i created ng-x-cli. Well pretty much it is angular-cli with all its features i like topped with DllPlugin.

Feel free to check it out whoever still experience bad performance.

P.S: currently it doesnt have a test runner, because i dont write tests

aegyed91 avatar Feb 01 '17 09:02 aegyed91

The rebuild performance has been vastly improved but it hasn't been released yet :) You'll see improvements when master is tagged.

After the stuff that's in master, the DLL only gave an additional 5% or so but there were issues with lazy-loading which can't be fixed until the way lazy-loading is done in Angular changes. Unless you managed it with ng-x-cli? I think @filipesilva has more details

intellix avatar Feb 01 '17 10:02 intellix

@intellix: When will the next release be? The current master is producing errors for me (Cannot find module '@ngtools/json-schema').

johannesjo avatar Feb 01 '17 11:02 johannesjo

@intellix ahh, i no longer use the master branch

there were issues with lazy-loading which can't be fixed until the way lazy-loading is done in Angular changes. Unless you managed it with ng-x-cli? I think @filipesilva has more details

Good idea, TBH i didnt run any benchmark / gave it any extra thought because the rebuilding time on my sucky laptop (os: win 10) was blazing fast.

Btw ng-x-cli is just a mix of: qdouble/angular-webpack2-starter's minimal branch and some features from angular-cli. Namely these features:

I also took the naming of different config keys ng-cli.config.js from angular-cli.json so i can transition back to angular-cli without any complications.

aegyed91 avatar Feb 01 '17 14:02 aegyed91

Try 28 guys. I've just compared my large project before and after and it's so much faster than 40% as advertised.

b26: 3.3sec average on save b28: 1.0sec average on save

intellix avatar Feb 01 '17 20:02 intellix