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

perf(synthetic-shadow): optimize recursivelySetShadowResolver #4088

Merged
merged 1 commit into from Mar 20, 2024

Conversation

nolanlawson
Copy link
Contributor

@nolanlawson nolanlawson commented Mar 20, 2024

Details

Optimizes the recursivelySetShadowResolver function to avoid calling childNodes and to use firstChild/nextSibling instead.

Browsers represent the DOM as a linked list under the hood, so this is faster.

This improves the dom-ss-slot-create-container-5k-this-change benchmark by 4-9%, and possibly some other synthetic-shadow benchmarks as well.

Screenshot 2024-03-20 at 1 36 58 PM

The reason this is important is because we set KEY__SHADOW_STATIC on the top level of a static fragment, which then causes us to recurse through the entire DOM structure to set the KEY__SHADOW_RESOLVER. (This is used for the legacy isNodeShadowed/isNodeFromTemplate as well as for the patched MutationObserver.) If we have a lot of static fragments, or if they are very deep, then we can spend a lot of time recursing.

Long-term, we should probably try to avoid this recursion entirely and just do the lookup on-demand when MutationObserver/isNodeShadowed is called: #4089

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

@nolanlawson nolanlawson requested a review from a team as a code owner March 20, 2024 20:42
@nolanlawson nolanlawson changed the title perf: optimize recursivelySetShadowResolver perf(synthetic-shadow): optimize recursivelySetShadowResolver Mar 20, 2024
@nolanlawson nolanlawson merged commit 989d810 into master Mar 20, 2024
9 checks passed
@nolanlawson nolanlawson deleted the nolan/optimize-recursively-set branch March 20, 2024 21:28
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

2 participants