Skip to content

Scaling to large codebases #1905

Closed
Closed

Description

@unindented

I have a codebase with ~2000 JS files (no loaders), ~500 CSS files (style!css!postcss!), and ~500 Mustache templates (mustache!). The build time on a beefy box is ~5min. What are my options to decrease this time?

The build is CPU-bound as far as I can tell. Webpack runs single-threaded, but I can't think of a way around that.

The thing is, on a certain build, only a handful of files have changed from the previous one. When webpack is in watch mode, it can rebuild super quickly (I'm guessing because it only builds the parts that are affected by the change). Couldn't the same strategy be applied to normal builds?

@sokra @bebraw Does anything in Webpack 2 address this? If it doesn't, could you give me some pointers on persisting the dependency tree across builds to achieve fast builds? Or maybe some other ideas that you have?

Activity

  1. unindented commented on Jan 19, 2016

    @unindented
    Author

    I'll look into that, thank you!

    Manually maintaining the list of files that don't change isn't ideal, so if you have plans for the future please let me know!

  2. bebraw commented on Jan 19, 2016

    @bebraw
    Contributor

    Manually maintaining the list of files that don't change isn't ideal, so if you have plans for the future please let me know!

    Maybe that's something that could be globbed?

  3. unindented commented on Jan 19, 2016

    @unindented
    Author

    For vendor files yes, but that's just a small part of this codebase...

  4. unindented commented on Jan 19, 2016

    @unindented
    Author

    I'll look into those too, thank you so much!

  5. Globegitter commented on Jan 19, 2016

    @Globegitter

    @unindented I guess this issue could be of interest to you as well: #250

  6. unindented commented on Jan 19, 2016

    @unindented
    Author

    @Globegitter thanks for the heads up!

  7. forkingpath commented on Jan 19, 2016

    @forkingpath

    Move source dirs in your config.module.resolve from moduleDirectories to root where possible - it should cut down quite a bit on compilation time on incremental compiles, since the aggregate delay of searching moduleDirectories seems to be significant. see #1574 and particularly #472 (comment)

  8. unindented commented on Jan 20, 2016

    @unindented
    Author

    @karlnp I only have node_modules in the moduleDirectories directive...

  9. unindented commented on Jan 20, 2016

    @unindented
    Author

    @bebraw Your advice to go back to version 0.14 of css-loader in some other thread was actually pretty effective. It has cut down the build time by ~30%.

  10. larryhe commented on Feb 9, 2016

    @larryhe

    Hi @unindented , did your build time get shorter? I have the similar issue as yours. Our project has a huge codebase with over 900 modules. rebuild the whole project takes about 3 minutes which is absolutely acceptable given that we have a huge code base. But the biggest problem is incremental build time is incredibly long and each time whatever file you change, you have to wait about 3 minutes for webpack to finish compile and bundle. I tried all the tips on http://webpack.github.io/docs/build-performance.html but seems not working. I thought it might be each of our chunk is too big or all the code mangled together and each file changed will cause the whole application to rebuilt. So I wrote a really small test file and split it out in entry file. But still whenever I change the test file, it took almost 3 minutes to build the test module, which does not make any sense at all. because incremental build is similar to rebuild. you said when webpack is in watch mode, it can rebuild super quickly. so my question is how many seconds is your incremental build? Could you share your webpack.config here? My webpack.config is as following. Did not get any ideas on how to shorten my incremental build yet. we didn't care too much about rebuild time though. Thanks.

    'use strict'
    var webpack = require('webpack')
    var path = require('path')
    var excludes = require('./excludes');
    
    
    module.exports = {
        'entry': {
            'common.base': ['cssua', 'jquery','backbone', 'underscore'],
            'entry1': 'entry1',
            'entry2': 'entry2',
            'entry3': 'entry3'
        },
        'output': {
            'pathinfo': true,
            'path': path.join(__dirname, 'dist'),
            'publicPath': '/resources/dist/',
            'filename': '[name].js'
        },
        cache: true,
        plugins: [
            new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),
            new webpack.ProvidePlugin({ _: 'underscore'}),
            new webpack.ProvidePlugin({ cssua: 'cssua'}),
            new webpack.optimize.CommonsChunkPlugin({name: 'common.base', minChunks: 2}),
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map',
                exclude: excludes,
                columns: false, // no columns in SourceMaps
                module: true // use SourceMaps from loaders
            })
        ],
        'resolve': {
            'root': [
                path.join(__dirname, './')
            ],
            'alias': {
                'cssua': 'lib/cssua',
                'backbone': 'lib/backbone/backbone',
                'underscore': 'lib/underscore/underscore',
                'backbone.paginator': 'lib/backbone.paginator/lib/backbone.paginator',
                'jquery': 'lib/jquery/dist/jquery',
                'snap.svg': 'lib/Snap.svg/dist/snap.svg'
            }
        },
        module: {
            'noParse': [/moment.js/, /base64.js/],
            'loaders': [
                {
                    test: /\.js$/,
                    loader: 'babel-loader',
                    exclude: excludes,
                    query: {
                        cacheDirectory: true,
                        presets: 'es2015',
                        compact: false
                    }
                },
                {
                    'test': /\.hbs$/,
                    'loader': 'handlebars-loader',
                    'query': {
                        runtime: 'handlebars/runtime',
                        helperDirs: [
                            __dirname + "/templates/helpers"
                        ],
                        partialDirs: [
                            __dirname
                        ]
                    }
                },
                {
                    'test': /base64/,
                    'loader': 'imports?this=>window'
                },
                {
                    'test': /snap.svg/,
                    'loader': 'imports?this=>window,fix=>module.exports=0'
                }
            ]
        }
    }
    
  11. abhinavsingi commented on Feb 13, 2016

    @abhinavsingi

    @larryhe @unindented : My codebase of >5k modules takes build time of ~10 minutes - same time gets spend on incremental builds - tried every optimization out there - all the cache methods too.
    But due to severe lack of documentation of webpack and it's codebase - it's very difficult to debug things as to what can be causing such slowness.
    css-loader downgrade did help.
    Is webpack even suitable for such huge codebases?

  12. unindented commented on Feb 15, 2016

    @unindented
    Author

    @larryhe @abhinavsingi Sorry for taking so long to respond, I missed the email notifications.

    In my experience, the value used for devtool is very important when rebuilding. I haven't used SourceMapDevToolPlugin, but maybe it's also the source of your issues?

    The config I use for webpack-dev-server looks like this:

    {
      "entry":{
        "xxx-requirejs-accounts-main":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/accounts_main.js"
        ],
        "xxx-requirejs-complete":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/complete.js"
        ],
        "xxx-requirejs-embed-aware-activation":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/embed_aware_activation.js"
        ],
        "xxx-requirejs-home-main":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/home_main.js"
        ],
        "xxx-requirejs-messages-main":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/messages_main.js"
        ],
        "xxx-requirejs-network-admin":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/network_admin.js"
        ],
        "xxx-requirejs-notes-main":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/notes_main.js"
        ],
        "xxx-requirejs-public-homepage-variant-a":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/public_homepage_variant_a.js"
        ],
        "xxx-requirejs-public-main":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/public_main.js"
        ],
        "xxx-requirejs-signup":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/main/signup.js"
        ],
        "xxx-dynamic-basic-bootstrap":[
          "./bootstrap/lib/environment/bootstrap_basic.js"
        ],
        "xxx-dynamic-cdn-bootstrap":[
          "./bootstrap/lib/environment/bootstrap_api.js"
        ],
        "xxx-platform-buttons":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/environment/platform_buttons.js",
          "./bootstrap/lib/environment/bootstrap_basic.js"
        ],
        "xxx-platform-feed":[
          "./bootstrap/lib/ready.js",
          "./bootstrap/lib/environment/platform_feed.js",
          "./bootstrap/lib/environment/bootstrap_basic.js"
        ],
        "platform_embed":[
          "./platform/lib/xxx_shim.js",
          "./platform/lib/embed_bootstrap.js",
          "./bootstrap/lib/environment/bootstrap_platform.js"
        ],
        "platform_js_sdk":[
          "jquery-real",
          "./platform/lib/xxx_shim.js",
          "./platform/lib/jquery_adapter.js",
          "./platform/lib/platform_session.js",
          "./platform/lib/embed_bootstrap.js",
          "./platform/lib/bootstrap.js",
          "./bootstrap/lib/environment/bootstrap_platform.js"
        ]
      },
      "output":{
        "path":"dist/releases/stable",
        "pathinfo":true,
        "filename":"[name].js",
        "chunkFilename":"[name].js"
      },
      "contentBase":"dist/releases/stable",
      "debug":true,
      "devtool":"eval",
      "watch":true,
      "stats":{
        "hash":false,
        "timings":false,
        "assets":false,
        "chunks":false,
        "modules":false,
        "reasons":true,
        "children":false
      },
      "resolve":{
        "extensions":[
          "",
          ".js"
        ],
        "modulesDirectories":[
          "node_modules"
        ],
        "alias":{
          "colorbox$":"vendor/lib/colorbox-1.3.15",
          "imagesloaded$":"imagesloaded/imagesloaded.pkgd",
          "jquery$":"core/lib/adapters/jquery_adapter",
          "jquery-real$":"jquery/dist/jquery",
          "org/cometd$":"cometd-jquery/org/cometd",
          "jquery-cometd$":"cometd-jquery/jquery/jquery.cometd",
          "jquery-datepicker$":"eyecon-datepicker/js/jquery.datepicker-2009.05.22",
          "jquery-dotdotdot$":"dotdotdot",
          "jquery-dragsort$":"dragsort",
          "jquery-truncate$":"truncate/jquery.truncate",
          "jquery-typeahead$":"typeahead",
          "jquery-watermark$":"core/lib/adapters/jquery_watermark_adapter",
          "jquery-watermark-real$":"jquery-watermark/jquery.watermark",
          "plupload$":"vendor/lib/plupload-2.1.6",
          "resig-class$":"resig_class/class",
          "socket.io$":"vendor/lib/socket.io-0.9.10",
          "squire-rte$":"squire-rte/build/squire-raw",
          "svg4everybody$":"svg4everybody/dist/svg4everybody",
          "triejs$":"triejs/src/trie",
          "twemoji$":"core/lib/adapters/twemoji_adapter",
          "twemoji-real$":"twemoji/twemoji.npm",
          "velocity$":"velocity-animate"
        }
      },
      "resolveLoader":{
        "extensions":[
          "",
          ".js"
        ],
        "modulesDirectories":[
          "grunt/lib/loaders",
          "node_modules"
        ],
        "alias":{
          "text":"raw-loader"
        }
      },
      "module":{
        loaders: [
          // Compile `.html` files as Mustache templates.
          {
            test: /\.html$/,
            exclude: /(assets\/pages|node_modules)\//,
            loader: 'mustache'
          },
          // Process `.css` files with PostCSS.
          {
            test: /\.css$/,
            exclude: /node_modules\//,
            loader: ExtractTextPlugin.extract('style', [
              'css',
              'postcss'
            ].join('!'))
          },
          // Process `.json` files as JSON.
          {
            test: /\.json$/,
            exclude: /node_modules\//,
            loader: 'json'
          },
          // Expose globals for Workfeed.
          {
            test: require.resolve('jquery'),
            loader: [
              'expose?$',
              'expose?jQuery'
            ].join('!')
          },
          // Allow loading of `video.js` on demand.
          {
            test: /\.(eot|svg|ttf|woff)$/,
            include: /node_modules\/([^\/]+\/)*video\.js\//,
            loader: 'file?name=[name]' + (!isDebug ? '-[hash:20]' : '') + '.[ext]'
          },
          {
            test: /\.css$/,
            include: /node_modules\/([^\/]+\/)*video\.js\//,
            loader: [
              'style',
              'css'
            ].join('!')
          },
          // Fix bad assumptions in external libraries.
          {
            test: require.resolve('imagesloaded/imagesloaded.pkgd'),
            loader: 'imports?this=>window'
          },
          {
            test: require.resolve('cometd-jquery/org/cometd'),
            loader: 'imports?this=>window'
          },
          {
            test: require.resolve('cometd-jquery/jquery/jquery.cometd'),
            loader: 'imports?this=>window'
          },
          {
            test: path.resolve(root, 'vendor/lib/plupload-2.1.6'),
            loader: 'imports?this=>window'
          }
        ]
      },
      plugins: [
        // Automatically provide dependencies to files expecting certain globals
        // to just be there.
        new webpack.ProvidePlugin({
          '$': 'jquery-real',
          'jQuery': 'jquery-real',
          'window.$': 'jquery-real',
          'window.jQuery': 'jquery-real',
          '_': 'underscore',
          'window._': 'underscore',
          'io': 'socket.io'
        }),
        // Define variables and replace them at compile time.
        new webpack.DefinePlugin({
          'process.env': {
            'NODE_ENV': JSON.stringify(environment),
          }
        }),
        // Extract CSS content into a separate file.
        new ExtractTextPlugin('[name]' + (!isDebug ? '-[contenthash:20]' : '') + '.css')
      ]
    }

    Build time is ~1min. Rebuild times are ~5s.

  13. 45 remaining items

  14. hccampos commented on Apr 20, 2017

    @hccampos

    Happy pack does not, and probably never will, work with TS

  15. MagicDuck commented on Apr 21, 2017

    @MagicDuck
    Contributor

    I see ... wasnt aware...

  16. designxtek commented on Apr 24, 2017

    @designxtek

    Wow Awesome-Typescript-Loader builds under 1 minute for me

  17. abergs commented on Jun 22, 2017

    @abergs

    @hccampos @MagicDuck @designxtek Happypack now supports TS

  18. modified the milestones: webpack 4, webpack 3 on Aug 12, 2017
  19. sokra commented on Aug 12, 2017

    @sokra
    Member

    Most of the things mentioned in this issue has been addressed for webpack 3 or are open PRs with breaking changes for webpack 4. Thanks for the investigations.

    If you have another idea for an improvement please open a new PR or issue.

    We also started a new documentation page with performance tips. It's far from complete, so if you want to contribute your experience here that would be great.

  20. pleerock commented on Jan 4, 2018

    @pleerock

    I have similar issues with as discussed in angular/angular-cli#5618 . Our project consist of around 2600 files and over 300 chunks and RemoveParentModulesPlugin execution takes about 1 hour. We are not able to use neither build neither serve processes without waiting an hour.

    First 10 minutes of CPU profiling of this process:

    webpack-perf-issues

  21. sokra commented on Jan 4, 2018

    @sokra
    Member

    @pleerock Please try with latest webpack version and open a new issue when this still occurs

  22. pleerock commented on Jan 4, 2018

    @pleerock

    @sokra do you mean latest 4 alpha version or latest 3.x version?

  23. MagicDuck commented on Jan 5, 2018

    @MagicDuck
    Contributor

    @pleerock i believe @sokra made some improvements to that plugin in 3.8.x

  24. pleerock commented on Jan 5, 2018

    @pleerock

    @MagicDuck those tests are from [email protected]

  25. MagicDuck commented on Jan 5, 2018

    @MagicDuck
    Contributor

    @pleerock 1 hour seems rather long for even the worst algorithm unless there is a very bad bug. I wonder if it's spending most of the time garbage collecting cause it's on the edge of the memory limit. Are you giving node enough memory? (max_old_space_size)

  26. pleerock commented on Jan 5, 2018

    @pleerock

    @MagicDuck yes, max_old_space_size is being set by me to 8gb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions