-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[webpack 5] rebuild is twice as slow comparing to webpack 4 #12102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for creating this issue. However, issues need to follow one of our templates so that we can clearly understand your particular circumstances. Please help us help you by recreating the issue using one of our templates. Please respect time of other developers |
Hello, I have the same issue here. I have compared build time with Webpack 4 and Webpack 5 on a project using Speed Measure Plugin and here is the result : As you can see, the time took by plugins ands loaders is about the same but Webpack 5 is twice slower than Webpack 4 is my case. |
@Thebarda please attach cpu profiles
|
I think bug in HtmlWebpackHarddiskPlugin |
Here is the cpuprofile for a Webpack 4 build And the cpuprofile for Webpack 5 build. Indeed @alexander-akait, for the webpack 5 build I'm using html-webpack-plugin on |
What is version of |
Why you run rebuild in |
What is node version? Node@10 has regression in perf |
@Thebarda Seems like you are talking about build performance and not rebuild performance. This issue is about rebuild performance, so seem like your issue is not similar to @meskill's issue, and I beg you to open an separate issue for your unrelated issue. It looks strongly like you are using persistent cache for terser-webpack-plugin in webpack 4 and measuring the cached build. While in webpack 5 you have to opt-in into persistent caching. Please make sure to remove |
@meskill i looked at your profile and noticed a few things:
So we are talking about 450ms extra for webpack 5.
|
@sokra Thanks, for the suggestions, I will check it. Also, I've changed the initial issue description with some simple repo to neglect our project-specific config - in this repo webpack4 and webpack5 use the same config for the react example project. P.S.: yes we already fixed the problem with long |
This is compatible with what I'm seeing in a large, multi entries app when I upgrade. Building is a bit slower (~18s to ~22s), rebuilding in watch mode is up to 3x slower. Development mode
webpack 4
webpack 5
|
Why you use |
@alexander-akait I see non-trivial improvements in CPU and memory usage using split chunks in development with webpack4. Anyways, taking
I'm really not sure which way to go. Webpack 4 is MUCH faster on rebuilds. |
On splitChunks in dev mode I see other people ran into the same issue and used the same solution:
|
Aside from worse compile times, has anyone noticed the larger memory build-up? On subsequent edits and re-bundling of my code my ram usage just keeps stacking up. |
@joeldenning with webpack-dev-server or simple bundle? |
I think you may have tagged me instead of @joshxyzhimself 😄 |
😸 😸 😸 @alexander-akait just simple bundle sir edit file -> recompile -> ram usage increase current workaround i do is kill the process and rerun it i was thinking of writing a plugin that exposes and calls const fs = require('fs');
const os = require('os');
const path = require('path');
const assert = require('assert');
const process = require('process');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const process_cwd = process.cwd();
const chunks_path = path.join(process_cwd, '.chunks.json');
const output_path = path.join(process_cwd, '/client-dist');
class chunk_extract_plugin {
constructor(mode) {
assert(typeof mode === 'string');
this.mode = mode;
}
apply(compiler) {
compiler.hooks.done.tap('Hello World Plugin', (stats) => {
const chunks_set = new Set();
if (this.mode === 'production') {
stats.compilation.chunks.forEach((chunk) => {
chunk.files.forEach((file) => {
if (path.extname(file) === '.js') {
chunks_set.add(file);
}
});
});
}
stats.compilation.entrypoints.forEach((entrypoint) => {
entrypoint.chunks.forEach((chunk) => {
chunk.files.forEach((file) => {
if (path.extname(file) === '.js') {
chunks_set.add(file);
}
});
});
});
const chunks_array = Array.from(chunks_set);
fs.writeFileSync(chunks_path, JSON.stringify(chunks_array, null, 2));
});
}
}
const Client = (env, argv) => {
const { mode } = argv;
return {
devtool: mode === 'development' ? 'source-map' : false,
entry: ['./client/client.jsx'],
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'eslint-loader',
options: {
fix: true,
cache: true,
emitWarning: true,
},
},
],
},
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(css)$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { importLoaders: 1 } },
{ loader: 'postcss-loader' },
],
},
{
test: /\.(woff(2)?|ttf|eot|otf|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({ ENVIRONMENT: JSON.stringify(mode) }),
new chunk_extract_plugin(mode),
],
optimization: {
runtimeChunk: true,
splitChunks: { chunks: 'all' },
minimize: mode === 'production',
minimizer: [
new TerserPlugin({
parallel: os.cpus().length,
terserOptions: {
output: { comments: false },
compress: { dead_code: true },
mangle: true,
},
}),
],
},
output: {
filename: mode === 'production' ? '[chunkhash].js' : '[name].js',
chunkFilename: mode === 'production' ? '[chunkhash].js' : '[name].js',
path: output_path,
publicPath: '/scripts/',
},
stats: 'minimal',
};
};
module.exports = [Client]; |
@joshxyzhimself if you create a new issue with a repro repo, we can help to find the memory leak. Please create a new issue as this is unreleated to the rebuild performance issue. |
@meskill do you update webpack to the latest 5 version? Maybe you can provide profile file? |
@meskill can you try latest webpack version and put feedback more here? |
@keepitterron Can you do the same and put feedback here, thanks |
How many? |
I tried to disable cacheUnaffected backCompat,waiting for me to try |
After the upgrade, HRM spends more time in building module |
I don't know what is |
Also |
@vue/cli-service is the cli provided by Vue, encapsulated some configuration items. |
Cache by the imported module name, can start a module separately |
Thank you for answering, I am trying to remove the vue-cli, use webpack5 directly, |
It should be deteriorated between different builds, i.e. if you run webpack and then stop and then run again, the value should be same |
no recent communication on this issue. |
@VishalBhandare-Apertumo Please provide profile as minimum (examples are above) |
We downgraded to webpack4 as seems there was this issue with webpack5. i have moved to new work now. But yes i need to find solution for this problem soon or later. i will communicating in this thread when i start working on fixing this. @alexander-akait you have been very actively helping people here. thanks a lot. I will get back to you while debugging issue if required. For Vue Cli users linking references |
Yes, will be great to profile and see there is perf problem (maybe in some loaders/plugins?) Feel free to ping me when you will do it |
Does ts-loader not support cache?
|
|
@FishOrBear Have you tried with Webpack's own filesystem cache? It's off (or rather in-memory only) by default.
should speed up subsequent starts considerably |
I have started in webpack.common.ts
|
Thanks for your reply, I know it's been stopped for maintenance, but if I don't use it(cache-loader), it's slow. |
lazy compilation makes compilation faster should we close this issue ? and open new issues more specific ? |
@sibelius this issue for tracking perf problems, because in some places we can have potentials improvements or bugs/memory leaks (but yes lazy compilation do your compiler faster) |
We noticed the big build/rebuild slowdowns on the big applications with a lot of dynamic imports. Webpack logs with dynamic imports100% (31840 affected + 0 infected of 31840) modules flagged as affected (31840 new modules, 0 changed, 0 references changed, 0 unchanged, 0 were not built) compute affected modules: 445.484298 ms finish modules: 19.2084 ms report dependency errors and warnings: 427.454098 ms optimize dependencies: 0.3432 ms create chunks: 4727.013482 ms 0% modules flagged as affected by chunk graph (31840 new modules, 0 changed, 0 unchanged) compute affected modules with chunk graph: 217.759399 ms optimize: 701.219197 ms 27958 modules hashed, 0 from cache (0.88 variants per module in average) module hashing: 1225.826896 ms 100% code generated (27956 generated, 0 from cache) code generation: 2767.025084 ms runtime requirements.modules: 229.206198 ms runtime requirements.chunks: 709.575096 ms runtime requirements.entries: 101.976499 ms runtime requirements: 1044.298593 ms hashing: initialize hash: 0.0097 ms hashing: sort chunks: 0.8831 ms hashing: hash runtime modules: 7641.072852 ms hashing: hash chunks: 2737.142484 ms hashing: hash digest: 1.9061 ms hashing: process full hash modules: 0.0078 ms hashing: 10394.245136 ms 100% code generated (23 generated, 0 from cache) record hash: 0.1943 ms module assets: 23.545 ms create chunk assets: 23352.211563 ms process assets: 13429.300045 ms And if I disable any dynamic imports by using Webpack logs with babel-dynamic-import100% (31840 affected + 0 infected of 31840) modules flagged as affected (31840 new modules, 0 changed, 0 references changed, 0 unchanged, 0 were not built) compute affected modules: 296.223434 ms finish modules: 15.761897 ms report dependency errors and warnings: 307.241732 ms optimize dependencies: 0.3177 ms create chunks: 544.269179 ms 0% modules flagged as affected by chunk graph (31840 new modules, 0 changed, 0 unchanged) compute affected modules with chunk graph: 213.570052 ms optimize: 643.424658 ms 27958 modules hashed, 0 from cache (0.88 variants per module in average) module hashing: 1230.355427 ms 100% code generated (27956 generated, 0 from cache) code generation: 4562.625918 ms runtime requirements.modules: 216.952694 ms runtime requirements.chunks: 38.561599 ms runtime requirements.entries: 4.5616 ms runtime requirements: 262.439893 ms hashing: initialize hash: 0.0094 ms hashing: sort chunks: 0.1772 ms hashing: hash runtime modules: 42.491898 ms hashing: hash chunks: 422.087988 ms hashing: hash digest: 0.9766 ms hashing: process full hash modules: 0.0032 ms hashing: 470.203986 ms 100% code generated (16 generated, 0 from cache) record hash: 0.1962 ms module assets: 18.619199 ms create chunk assets: 2269.294433 ms process assets: 877.657474 ms
|
enable |
very fast |
Great work |
can we close this ? |
I think yes, we can close, if somebody encounters to perfomance problems - feel free to open a new issue |
Did you resolved this not by use |
After upgrading to webpack 5 in our project we noticed that rebuild time increased more than 2 times comparing to webpack 4.
I've created a test repo https://github.com/meskill/webpack5-performance-issue to show the difference in rebuild time for webpack4 and webpack5.
It shows more than 2-time slowness of rebuild in webpack5 compare to webpack4. Profiling shows similar info


Cpuprofile for both webpack4 and webpack5
The text was updated successfully, but these errors were encountered: