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

@asadsahi of that I'm not sure. I tested it by manually editing the webpack-build-typescript.js file in my angular-cli installed in node_modules. Which version of awesome-typescript-loader do you have installed? If you can't get it working you might want to ask or open a ticket in that repo.

texel avatar Nov 04 '16 18:11 texel

I've noticed some progress on this issue. @filipesilva Could you please update npm package? I have a big project with a lot of components and want to check rebuild time, because now it takes about 20-40 seconds.

sharok avatar Nov 06 '16 09:11 sharok

I tried using Brunch, and got that results:

$ brunch w -s
07 Nov 12:38:08 - info: application started on http://localhost:3333/
07 Nov 12:38:11 - info: compiling
07 Nov 12:38:12 - info: compiled 239 files into 3 files, copied index.html in 4.8 sec
07 Nov 12:38:57 - info: compiled home.component.ts and 9 cached files into main.js in 107 ms

It lacks of functional in comparison with angular-cli, but it is much faster. 💨

rand0me avatar Nov 07 '16 09:11 rand0me

@rand0me as you just introduced me to Brunch and it caught my attention while looking at your stats. I tried this repo with angular and here are my stats:

> brunch watch --server
07 Nov 09:59:21 - info: application started on http://localhost:3333/
07 Nov 09:59:24 - info: compiling
07 Nov 09:59:24 - info: compiled 239 files into 3 files, copied index.html in 4.3 sec
07 Nov 10:00:03 - info: compiled home.component.html and 3 cached files into app.css in 234 ms
07 Nov 10:00:07 - info: compiled home.component.html and 3 cached files into app.css in 82 ms
07 Nov 10:00:14 - info: compiled home.component.html and 3 cached files into app.css in 93 ms
07 Nov 10:01:59 - info: compiled home.component.ts and 9 cached files into main.js in 106 ms
07 Nov 10:02:07 - info: compiled home.component.ts and 9 cached files into main.js in 98 ms

That is Nitro fast. 93ms with a html change and 106 ms with a typescript change.

Will it be correct to say that Brunch is on top of the list for recompiling assets, compared to webpack, systemjs, gulp etc at this point in time?

asadsahi avatar Nov 07 '16 10:11 asadsahi

Just a quick test I made today comparing the the https://github.com/AngularClass/angular2-webpack-starter:

Angular webpack: 1.5s with their base project Angular cli: 4.1s with the ng new base project

Both run on MacOS 10.12.1

albanx avatar Nov 07 '16 11:11 albanx

I tested gulp, brunch, and optimized angular cli (forkCheck), both on very small seed/template.

  • angular-cli : including forkCheck optimization I'm down to ~2-4 sec recompile time (~2 time faster than default).
  • angular class starter : 1.5~3.5 sec (it uses webpack)
  • gulp : 2 sec when it recompile typescript (but very fast when to recompile html < 200ms).
  • brunch : I just discovered thanks to @rand0me : ~120ms to recompile typescript !! This build tool looks very fast & simple to configure.

noguespi avatar Nov 07 '16 12:11 noguespi

@serphacker, @asadsahi I'm wondering, why people doesn't got it earlier😄 Now I'm trying to adopt a project, builded on top of angular-cli 1.0.0-beta.17 to be built with Brunch Things that I'm currently stuck to:

  • Can't do backward-compatible config, because of Brunch convetions
  • Can't make automatic injection of styles and scripts (to index.html)
  • Can't find Brunch plugin to support CSS @import concatenation
  • Also, it lacks a generate command, but it can be used from angular-cli 🙉

rand0me avatar Nov 07 '16 12:11 rand0me

@rand0me since the whole universe is after webpack/angular-cli combinations, I am not sure its wise to individually mix something with this, unless a plugin model with angular cli allows to use any build/package manager like webpack, brunch.

However, as an alternative approach to pick Brunch for a project perhaps is worth trying (which I will try as well).

I am sure angular-cli team is trying to identify the possible cause of slow rebuild (like @texel found in terms of forkCheck), but I suspect its webpack 2 not working to best of its abilities. I have managed to get rougly 200-300ms of rebuilds times from Webpack 1 using DLLS in the past, but since I have upgraded the same project on webpack 2, its down to 5-6 seconds. Couldn't find a single project with webpack 2 and dll giving rebuilds in milli seconds (Love to see one). There is a similar issue I have raised in the past but haven't got any answer.

asadsahi avatar Nov 07 '16 12:11 asadsahi

My rebuild takes about 8-10 seconds for a minimal app, which simply has 2 basic components. This is quite frustrating. Furthermore, even the ng --help command is slow. nv --version returns: angular-cli: 1.0.0-beta.19-3 node: 6.9.1 os: win32 x64 I concur with previous comments that anything over 2 seconds really leads to contemplating alternative approaches. It would be great if this can be easily resolved, as the idea behind angular-cli is fantastic.

phil-cap avatar Nov 11 '16 09:11 phil-cap

Yup, even ng version is slow for some reason, takes a few seconds. Maybe due to some file watcher thingy I don't know why it fires even for just checking the version.

Meligy avatar Nov 11 '16 10:11 Meligy

ng version taking some time is due to some module discovery code going on. It's something we're looking at removing as well.

filipesilva avatar Nov 11 '16 12:11 filipesilva

BTW, The slow rebuild issue mentioned here was becasue I was using awesome-typescript-loader. ts-loader seems to be 4 times faster. Raised with awesome-typescript-loader owner to see if any particular option has been missed.

asadsahi avatar Nov 14 '16 17:11 asadsahi

@asadsahi So side-by-side, if you simply replace awesome-typescript-loader with ts-loader, what are the numbers like? What are the numbers like?

intellix avatar Nov 15 '16 09:11 intellix

@intellix

With ts-loader: image

With awesome-typescript-loader: image

asadsahi avatar Nov 15 '16 09:11 asadsahi

What does your node_modules/angular-cli/models/webpack-build-typescript.js look like. Did you have to change anything else? As we don't have HMR out of the box :)

intellix avatar Nov 15 '16 09:11 intellix

@intellix I have 2 projects, one cli based and a .net non-cli based. In my above comments numbers are from the .net one using latest beta version of webpack 2 (beta 26). Not sure how I can test this with cli based project, but I am asuming something worth trying replacing awesome-typescript-loader with ts-loader to see any difference.

asadsahi avatar Nov 15 '16 09:11 asadsahi

@asadsahi When will the fix for everyone?

I tried to change loader, but receive many erros on build.

khoden avatar Nov 15 '16 09:11 khoden

@KhodeN I haven't tried in a project based on angular-cli. My above observation is from a non-cli based project.

asadsahi avatar Nov 15 '16 09:11 asadsahi

ts-loader has received a large number of improvements over the last couple weeks and it appears that awesome-typescript-loader may be merging functionality back into it.

With the latest version of ts-loader (1.2.1 as of now) and a quick replacement in the CLI, I was able to see a ~50% improvement on rebuild times (initial build increased ~25%). Be aware that some loader options are named differently (tsconfig -> configFileName) and for tsconfig paths support the ATL paths plugin is still needed. It also seems to be pulling in the spec files (or at least type checking them); so that will need some investigation (the exclude line is still in the config).

NOTE: Production builds are broken with the change. The loader seems to have a conflict with the use of LoaderOptionsPlugin.

clydin avatar Nov 15 '16 14:11 clydin

@clydin 50% is massive difference. Is it worth switching to ts-loader in cli then?

In my case I don't have to make any change to any path/configuration. Just replaced ATL with ts-loader.

asadsahi avatar Nov 17 '16 13:11 asadsahi