webpack-contrib / webpack-hot-middleware

Webpack hot reloading you can attach to your own server
MIT License
2.34k stars 296 forks source link

perf: option to exclude cached from stats #441

Closed SuperOleg39 closed 11 months ago

SuperOleg39 commented 1 year ago

This PR contains a:

Motivation / Use-Case

stats.toJson is a heavy method, and is called for every incremental build.

I made a webpack build performance profiling, and found that stats.toJson from webpack-hot-middleware takes around 50ms work - while complete incremental build for small change is cost around 200-250ms fo CPU work.

After trying to change statsOptions, I found that cached: true option is the slowest, and with disabled cached: false full stats.toJson call cost around 10ms - five times faster.

Looks like we don't need this option for most projects, but for backward compatibility I just add one parameter to rewrite it.

Breaking Changes

This PR is backward compatible with previous changes in https://github.com/webpack-contrib/webpack-hot-middleware/pull/336

Additional Info

CPU profiles included tramvai-cli.cached-false.cpuprofile.zip tramvai-cli.cached-true.cpuprofile.zip

No cached:

Снимок экрана 2023-08-01 в 18 52 46

And cached, as default:

Снимок экрана 2023-08-01 в 18 52 58
linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

SuperOleg39 commented 1 year ago

@alexander-akait Hello! Want to ask you for PR review 🙏

SuperOleg39 commented 1 year ago

I am fine with it, I will merge and release this tomorrow, I want to look at code why it is slow and maybe we need to put TODO about change it in the future major release

Thanks a lot!

Say if you need any CPU profile traces for debugging.

SuperOleg39 commented 1 year ago

@alexander-akait hello! Can you merge and release this fix please?

SuperOleg39 commented 11 months ago

@alexander-akait hello! Just want to remind about thix fix 🙏

alexander-akait commented 11 months ago

Sorry for delay, I will do releasae tomorrow

alexander-akait commented 11 months ago

@SuperOleg39 Hm, until I released it, maybe we can make it more flex, let's allow to override stats options (make an option for this) and use const statsOptions = { /* Default options */ children: true, ...opts.statsOptions }, so you can override everything and make it even faster

SuperOleg39 commented 11 months ago

@SuperOleg39 Hm, until I released it, maybe we can make it more flex, let's allow to override stats options (make an option for this) and use const statsOptions = { /* Default options */ children: true, ...opts.statsOptions }, so you can override everything and make it even faster

@alexander-akait Something like this? https://github.com/webpack-contrib/webpack-hot-middleware/pull/444