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

@kondi you might be right, I am just mentioning following times, as rebuild times. Time: 4127ms Time: 3508ms

Another thing I was just keeping an eye on was how quickly browser gets refreshed after rebuild, and couldn't see significant differences. It might be something my head doesn't want to accept or illusion becasue I have another project based on webpack 1 with dll and that project's rebuild is 200-300 milliseconds, which I am hoping webpack 2 to have same stats one day :)

Your numbers look much better by default already. Maybe because I am testing on windows? Or slow computer?

Its definitely becasue testing I did was on my work machine which is and 8 core beefy machine. On my home laptop it comes down to same numbers (around 10+ seconds). Both work and personal machines are on windows BTW.

asadsahi avatar Nov 03 '16 13:11 asadsahi

I just discovered that the awesome-typescript-loader forkChecker option isn't being passed properly, so it's not forking and type checking is happening inline. Changing useForkChecker to forkChecker in the webpack config drops reload time on a pristine project from ~4sec to ~1.5sec for me. I'll prepare a PR right now.

texel avatar Nov 03 '16 18:11 texel

@texel whoa that's impressive, great find! Let me know when that PR is up so I can review.

filipesilva avatar Nov 03 '16 18:11 filipesilva

Funny that the whole reason of typescript is to not have this type of mistakes. Similar improvement for me as well. From 5.5 sec to 2.2 sec. If you combine with dll option, ends up at 1.2 sec.

kondi avatar Nov 03 '16 18:11 kondi

@filipesilva https://github.com/angular/angular-cli/pull/3008

Just getting the CLA sorted.

texel avatar Nov 03 '16 18:11 texel

Just did a few numbers to check everything with 19-3 using forkChecker:

reload:

  • 6s -> 4s
  • 3s -> 1.7s
  • 3s -> 1.7s

ng test reloads with 133 tests:

  • 9s -> 6s
  • 6.5s -> 5s
  • 6.5s -> 4.15s

Would love to know the lowdown on using DLLs. To me it seems an obvious fix with the various frameworks being huge but haven't heard anything from anyone about why it's not used. Any ideas @TheLarkInn?

intellix avatar Nov 03 '16 18:11 intellix

I haven't tested the DLL, but have tested https://github.com/mzgoddard/hard-source-webpack-plugin and noticed no improvement almost.

filipesilva avatar Nov 03 '16 18:11 filipesilva

https://github.com/mzgoddard/hard-source-webpack-plugin shouldn't be an improvement from an in-memory reload, but it should significantly reduce initial compile times.

texel avatar Nov 03 '16 18:11 texel

@texel does this mean it'd always be notable in ng build?

Meligy avatar Nov 03 '16 18:11 Meligy

DLL potentially complicates building the bundle (it has to be done in two steps, and the main bundle needs to be told how to reference the DLL) and it may slightly increase initial build time, but in my experience it's a win for dev speed and hopefully makes caching libs easier as well.

texel avatar Nov 03 '16 18:11 texel

Yes, https://github.com/mzgoddard/hard-source-webpack-plugin seems like it improves builds after initial build.

Meligy avatar Nov 03 '16 19:11 Meligy

The DLL option also severely limits webpack's tree-shaking ability. So for production builds it's probably not the best option. I've been experimenting with moving angular into a DLL as well. While there is additional complexity, it seems an overall win for at least the dev serve use case.

clydin avatar Nov 03 '16 19:11 clydin

@texel

Changing useForkChecker to forkChecker in the webpack config

Can we somehow test this in an existing cli based project?

Is this setting something we can try in a non-cli, webpack 2 based project? I have similar slow rebuilds issue in another project.

asadsahi avatar Nov 03 '16 20:11 asadsahi

@texel's tweak effectively cuts my build time in half and this is on a larger project. Well done!

jmlivingston avatar Nov 03 '16 21:11 jmlivingston

@asadsahi certainly! If you're using awesome-typescript-loader you just need to make sure that forkChecker: true is passed in its query params. You'll also need to make sure to instantiate a new ForkCheckerPlugin and add it to the plugins array of your webpack config.

texel avatar Nov 03 '16 23:11 texel

Opened a new PR to satisfy the googlebot: https://github.com/angular/angular-cli/pull/3011

texel avatar Nov 03 '16 23:11 texel

@texel unfortunately this isnt't making any difference. Here is my repo:

This is my configuration:

forkChecker parameter:

module.exports = merge({
    resolve: {
        extensions: ['.js', '.ts']
    },
    module: {
        rules: [
            { test: /\.ts$/, exclude: [/\.(spec|e2e)\.ts$/], loaders: ['awesome-typescript-loader?forkChecker=true ', 'angular2-template-loader'] },
            { test: /\.html$/, loader: "html" },
            { test: /\.css/, loader: extractCSS.extract(['css']) },
            { test: /\.scss$/, loaders: ['raw-loader', 'sass-loader?sourceMap'] },
            { test: /\.json$/, loader: 'json-loader' },
            {
                test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
   ............for brevity

Plugin added:

  plugins: [
        extractCSS,
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('../wwwroot/dist/vendor-manifest.json')
        }),
        // To eliminate warning
        // https://github.com/AngularClass/angular2-webpack-starter/issues/993
        new webpack.ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            __dirname
        ),
        /*
            * Plugin: ForkCheckerPlugin
            * Description: Do type checking in a separate process, so webpack don't need to wait.
        */
        new ForkCheckerPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                'ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT)
            }
        })

Can you see any obvious mistake?

asadsahi avatar Nov 04 '16 09:11 asadsahi

#3011 merged which should help with build/rebuild times. Many thanks to @texel for finding this bug!

filipesilva avatar Nov 04 '16 16:11 filipesilva

@asadsahi that should work for a Webpack 1 project- does Webpack 2 still support query params using the url-style syntax?

texel avatar Nov 04 '16 17:11 texel

@texel not sure. But I also tried with following settings with no luck. Are these correct settings?

{
              loader: 'awesome-typescript-loader',
              query: {
                forkChecker: true
              }
            },

Besides this project, how can I test the merged PR change for fast rebuilds in an angular-cli based project right now? (any way I can target my project using latest version of cli codebase?)

asadsahi avatar Nov 04 '16 17:11 asadsahi