webpack 4 compilation speed is slower than webpack 2

Bug report

What is the current behavior?
In webpack 4 process.nextTick will run after 10 ~ 11ms, but in webpack 2 it will run after 1 ~ 2ms.

If the current behavior is a bug, please provide the steps to reproduce.

webpack@4.17.1 webpack/lib/NormalModuleFactory.js at line 335

if (err) return callback(err);

loaders = results[0].concat(loaders, results[1], results[2]);
let now = +new Date();
process.nextTick(() => {
    let tmp = +new Date();
    console.log('nextTick: ', tmp - now);
    const type = settings.type;
    const resolveOptions = settings.resolve;
    ......
});

process.nextTick takes 10~11ms.

However, webpack@2.3.3 webpack/lib/NormalModuleFactory.js at line 186

let now;
async.parallel([
    ...
], function(err, results) {
    if(err) return callback(err);
    loaders = results[0].concat(loaders).concat(results[1]).concat(results[2]);
    now = +new Date();
    process.nextTick(onDoneResolving);
});

function onDoneResolving() {
    let tmp = +new Date();
    console.log('nextTick: ', tmp - now);
    callback(null, {
        ...
    });
}

process.nextTick takes 1~2ms.

The config file and JS resource is same, but webpack@4 is slower. Why? If there are more and more process.nextTick, webpack 4 will become slower and slower. The problem appears when call runAsChild to compile by html-webpack-plugin.

What is the expected behavior?

Other relevant information:
webpack version: 4.17.1
Node.js version: 8.9.4
Operating System: Mac
Additional tools:

Author: Fantashit

1 thought on “webpack 4 compilation speed is slower than webpack 2

  1. I can’t see how measuring a “random” nextTick in the code base is in any relation about the overall performance. The event loop is probably more busy at this time.

Comments are closed.