Skip to content

chore: improve performance of DOM traversal operations #12863

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

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Aug 15, 2024

Interestingly, we used to have this optimisation but we removed them as we thought they didn't improve performance. It turns out that we were wrong and they actually do and it was likely that Chrome 125 was had a regression. Specifically we can avoid a nasty V8 deopt on one of the most expensive hot paths in the codebase.

Megamorphic deopt

Screenshot 2024-08-15 at 16 55 43

Monomorphic, no deopts

Screenshot 2024-08-15 at 16 53 59

Copy link

changeset-bot bot commented Aug 15, 2024

🦋 Changeset detected

Latest commit: 39acd8d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -116,7 +116,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
var parent_node = /** @type {Element} */ (node);

anchor = hydrating
? set_hydrate_node(/** @type {Comment | Text} */ (parent_node.firstChild))
? set_hydrate_node(/** @type {Comment | Text} */ (get_first_child(parent_node)))
Copy link
Member

Choose a reason for hiding this comment

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

In #12863 (comment) I was referring to these calls too. Isn't parent_node.firstChild preferable? Surely get_first_child is polymorphic (megamorphic?), given we call it with different node types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-08-15 at 18 36 43

All the IC call-sites that use these functions come back as inlined so they're not really in the JIT code.

@Rich-Harris Rich-Harris merged commit 72c51e3 into main Aug 15, 2024
9 checks passed
@Rich-Harris Rich-Harris deleted the mono-node-traversal branch August 15, 2024 21:15
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.

2 participants