xz64 / license-webpack-plugin

Outputs licenses from 3rd party libraries to a file
ISC License
165 stars 51 forks source link

Performance regression on Webpack 5 #92

Closed silverwind closed 3 years ago

silverwind commented 3 years ago

I noticed the plugins performs considerably worse on Webpack 5 vs. Webpack 4. A build that previously took 4 minutes took over 9 minutes and I've narrowed down the regression to this plugin.

Some of that slowness can be attributed to Webpack 5 which in my testing shows around a 15-20% performance regression compared to Webpack 4, but there certainly seems to be something about this plugin.

xz64 commented 3 years ago

I did not see a significant change in performance during my testing. I suspect it could be to the iteration of stats here https://github.com/xz64/license-webpack-plugin/blob/master/src/WebpackChunkModuleIterator.ts#L23

Can you try removing this portion of code from node_modules/license-webpack-plugin/dist/WebpackChunkModuleIterator.js and check the performance?

            var stats = compilation.getStats().toJson();
            var statsModules = this.statsIterator.collectModules(stats, chunk.name);
            try {
                for (var statsModules_1 = __values(statsModules), statsModules_1_1 = statsModules_1.next(); !statsModules_1_1.done; statsModules_1_1 = statsModules_1.next()) {
                    var module_2 = statsModules_1_1.value;
                    callback(module_2);
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (statsModules_1_1 && !statsModules_1_1.done && (_d = statsModules_1.return)) _d.call(statsModules_1);
                }
                finally { if (e_2) throw e_2.error; }
            }

I can also try caching the stats if this is causing the issue

markjm commented 3 years ago

@xz64 thanks for the starting point. I checked out this part of code and determined it to be the issue in our project. I posted a fix in #94

xz64 commented 3 years ago

A fix is published in v2.3.11