fix(perf): avoid superfluous timer wrappings in watch mode#5114
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## master #5114 +/- ##
==========================================
- Coverage 98.94% 98.93% -0.02%
==========================================
Files 226 226
Lines 8429 8431 +2
Branches 2314 2315 +1
==========================================
+ Hits 8340 8341 +1
Misses 32 32
- Partials 57 58 +1
|
lukastaegert
left a comment
There was a problem hiding this comment.
Thank you for spotting is. The only issue I see with your implementation is that isWithTimers now is global state, which means that completely unrelated runs will now also influence each other. Basically if you have a config file with an array of configs, only the plugins in the first config will be instrumented.
Maybe a cleaner approach would be to leave a flag on each instrumented plugin in getPluginWithTimers, e.g.
function getPluginWithTimers(plugin: any, index: number): Plugin {
if (plugin._hasTimedHooks) return plugin;
plugin._hasTimedHooks = true;
for (const hook of TIMED_PLUGIN_HOOKS) {
if (hook in plugin) {One could also use a Symbol to hide the flag, or keep a Set<Plugin> of instrumented plugins as global state. What do you think?
lukastaegert
left a comment
There was a problem hiding this comment.
I changed your code as I suggested and will merge it now.
|
This PR has been released as part of [email protected]. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
In watch mode, every time bundle starts, inputOptions.plugins will be wrapped in another layer of timer, which will cause incorrect performance timings.