Skip to content
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

fix(perf): avoid superfluous timer wrappings in watch mode #5114

Merged
merged 3 commits into from Sep 10, 2023

Conversation

ZhengLiu2825
Copy link
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

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.

@vercel
Copy link

vercel bot commented Aug 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2023 5:09am

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #5114 (d3af65f) into master (e9fef3f) will decrease coverage by 0.02%.
The diff coverage is 50.00%.

@@            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     
Files Changed Coverage Δ
src/utils/timers.ts 91.07% <50.00%> (-1.53%) ⬇️

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed your code as I suggested and will merge it now.

@lukastaegert lukastaegert merged commit 1d0c6be into rollup:master Sep 10, 2023
9 of 11 checks passed
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.29.1. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants