You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
Reacted by Glen, Dan Bovey, Ed Morley, Glavin Wiechert, Ben Creasy, Max Milton, Joel, Dmitry Gonchar, Marcin and An Yan
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)
@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%.
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.
@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?
@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.newwebpack.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.newwebpack.DefinePlugin({'process.env': {'NODE_ENV': JSON.stringify(environment),}}),// Extract CSS content into a separate file.newExtractTextPlugin('[name]'+(!isDebug ? '-[contenthash:20]' : '')+'.css')]}
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.
Reacted by Jason Harper, YiJun, Joel, Hayden, Dmitry Gonchar, zheng, Bnaya Peretz, August “Kai” Kaiser, Dmitriy, Glavin Wiechert and 3 more
Reacted by Jesse Stuart, Adam Rackis, YiJun, Bnaya Peretz, August “Kai” Kaiser, Glavin Wiechert, John Darryl Pelingo and Di Fan
Reacted by Sashe Klechkovski, lllccc, Anton Vynogradenko, Jesse Stuart, Adam Rackis, YiJun, Dan Bovey, Bnaya Peretz, August “Kai” Kaiser, Glavin Wiechert and 1 more
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:
@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)
Activity
bebraw commentedon Jan 19, 2016
Maybe
DllPlugincould fit your use case? See https://webpack.github.io/docs/build-performance.html and https://github.com/webpack/webpack/tree/master/examples/dll .unindented commentedon Jan 19, 2016
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!
bebraw commentedon Jan 19, 2016
Maybe that's something that could be globbed?
unindented commentedon Jan 19, 2016
For vendor files yes, but that's just a small part of this codebase...
bebraw commentedon Jan 19, 2016
Ok. Here's one direction: https://github.com/amireh/happypack, https://github.com/trivago/parallel-webpack .
unindented commentedon Jan 19, 2016
I'll look into those too, thank you so much!
Globegitter commentedon Jan 19, 2016
@unindented I guess this issue could be of interest to you as well: #250
unindented commentedon Jan 19, 2016
@Globegitter thanks for the heads up!
forkingpath commentedon Jan 19, 2016
Move source dirs in your config.module.resolve from
moduleDirectoriestorootwhere 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)unindented commentedon Jan 20, 2016
@karlnp I only have
node_modulesin themoduleDirectoriesdirective...unindented commentedon Jan 20, 2016
@bebraw Your advice to go back to version
0.14ofcss-loaderin some other thread was actually pretty effective. It has cut down the build time by ~30%.larryhe commentedon Feb 9, 2016
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.
abhinavsingi commentedon Feb 13, 2016
@larryhe @unindented : My codebase of
>5k modulestakes 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
webpackand it's codebase - it's very difficult to debug things as to what can be causing such slowness.css-loaderdowngrade did help.Is
webpackeven suitable for such huge codebases?unindented commentedon Feb 15, 2016
@larryhe @abhinavsingi Sorry for taking so long to respond, I missed the email notifications.
In my experience, the value used for
devtoolis very important when rebuilding. I haven't usedSourceMapDevToolPlugin, but maybe it's also the source of your issues?The config I use for
webpack-dev-serverlooks like this:Build time is ~1min. Rebuild times are ~5s.
45 remaining items
hccampos commentedon Apr 20, 2017
Happy pack does not, and probably never will, work with TS
MagicDuck commentedon Apr 21, 2017
I see ... wasnt aware...
designxtek commentedon Apr 24, 2017
Wow Awesome-Typescript-Loader builds under 1 minute for me
abergs commentedon Jun 22, 2017
@hccampos @MagicDuck @designxtek Happypack now supports TS
sokra commentedon Aug 12, 2017
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.
pleerock commentedon Jan 4, 2018
I have similar issues with as discussed in angular/angular-cli#5618 . Our project consist of around 2600 files and over 300 chunks and
RemoveParentModulesPluginexecution takes about 1 hour. We are not able to use neitherbuildneitherserveprocesses without waiting an hour.First 10 minutes of CPU profiling of this process:
sokra commentedon Jan 4, 2018
@pleerock Please try with latest webpack version and open a new issue when this still occurs
pleerock commentedon Jan 4, 2018
@sokra do you mean latest 4 alpha version or latest 3.x version?
MagicDuck commentedon Jan 5, 2018
@pleerock i believe @sokra made some improvements to that plugin in 3.8.x
pleerock commentedon Jan 5, 2018
@MagicDuck those tests are from [email protected]
MagicDuck commentedon Jan 5, 2018
@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)
pleerock commentedon Jan 5, 2018
@MagicDuck yes, max_old_space_size is being set by me to 8gb