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

#5176: fix await element performance regression #5177

Merged
merged 4 commits into from Feb 13, 2023

Conversation

twschiller
Copy link
Contributor

What does this PR do?

Checklist

  • Add tests
  • Designate a primary reviewer: @BLoe

@twschiller twschiller added this to the 1.7.19 milestone Feb 11, 2023
@twschiller twschiller changed the title #5176: await element performance #5176: fix await element performance regression Feb 11, 2023
@codecov
Copy link

codecov bot commented Feb 11, 2023

Codecov Report

Merging #5177 (7cbb8ae) into main (d7d9924) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #5177      +/-   ##
==========================================
- Coverage   61.18%   61.18%   -0.01%     
==========================================
  Files         984      984              
  Lines       30440    30440              
  Branches     5870     5870              
==========================================
- Hits        18626    18625       -1     
- Misses      11814    11815       +1     
Impacted Files Coverage Δ
src/pageEditor/hooks/useExtensionTrace.ts 75.75% <0.00%> (-3.04%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -163,6 +163,7 @@
},
"devDependencies": {
"@fortawesome/fontawesome-common-types": "^0.2.36",
"@shopify/jest-dom-mocks": "^4.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Includes mocks for requestIdleCallback. I think we could also use for location mock instead of the other we added a couple weeks ago

Comment on lines +89 to +96
if (isMatchinInProgress) {
return;
}

// Don't accumulate idle callbacks
if (idleCallbackHandle) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isMatchinInProgress) {
return;
}
// Don't accumulate idle callbacks
if (idleCallbackHandle) {
return;
}
// Don't accumulate idle callbacks
if (isMatchinInProgress || idleCallbackHandle) {
return;
}

// Wrap in requestIdleCallback to prevent impacting performance
idleCallbackHandle = requestIdleCallback(
() => {
requestAnimationFrame(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We are probably good to go without the requestAnimationFrame inside requestIdleCallback. The callback of requestIdleCallback is only called when browser has no tasks in the queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The callback of requestIdleCallback is only called when browser has no tasks in the queue.

It can also run in the timeout for requestIdleCallback is called. It waits a maximum of 150ms

idleCallbackHandle = null;
});
},
{ timeout: 150 }
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for the nested timeout? Should we just throttle for 150 milliseconds instead?
Personally, I struggle to predict how multiple timeouts will work, this make them hard for me to maintain and test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original code throttled to calls every 150 ms.

Personally, I struggle to predict how multiple timeouts will work

Agree, I think multiple are to be avoided. The way to think about this code now is:

  • Called every 150 ms
  • But will only run if idle, or 150 ms, whichever occurs first

So when page is non-idle, runs at most every 300ms. The requestIdle timeout I added because I'm not confident how Chrome calculates idle, so wanted to have a stop gap

@github-actions
Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@BALEHOK
Copy link
Contributor

BALEHOK commented Feb 13, 2023

Can we compare the performance of main with this branch? Are there actual improvements?

@twschiller
Copy link
Contributor Author

twschiller commented Feb 13, 2023

Can we compare the performance of main with this branch? Are there actual improvements?

I tested it on GitHub, and I at least perceived it to be faster. There's a couple other sites I'm going to try.

There's a chance that the mutation observer itself is an issue on some sites (especially because of the subtree). If we're still seeing performance issues, could use the mutation observer to queue up elements to check

We don't have a way of quantifying PixieBrix's impact on site performance yet. But definitely something I want to figure out how to add the in the future so we can warn users on inefficient selectors/triggers.

Adding performance timings to the mutation observer and throttled whole-document check would likely be the way to go there

@twschiller
Copy link
Contributor Author

Merging this in for additional testing as part of 1.7.19 QA

@twschiller twschiller merged commit 41f3d85 into main Feb 13, 2023
@twschiller twschiller deleted the feature/5176-await-element branch February 13, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

awaitElement performance regression in 1.7.16
2 participants