perf: walk composedPath() directly in delegated event propagation#18268
Merged
dummdidumm merged 2 commits intoMay 21, 2026
Conversation
The propagation walk in `handle_event_propagation` already calls `event.composedPath()` at the start to find the entry index, but then re-derives the same chain step-by-step via `current_target.assignedSlot || current_target.parentNode || .host`. Three property reads per iteration is measurable on the hot event path. Walk the captured `path` array by index instead. composedPath is the spec-compliant snapshot of the dispatch chain — same shadow-DOM and slot crossings as the manual walk, and arguably more correct in the edge case where a handler removes a parent mid-dispatch (the snapshot continues; the manual walk would stop at a null parent). Measured ~+13% in real Chromium on a click through a 30-deep tree with five delegated handlers. All 6006 runtime tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: b5ceea0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dummdidumm
approved these changes
May 21, 2026
dummdidumm
left a comment
Member
There was a problem hiding this comment.
thank you! makes the code simpler aswell
Merged
Rich-Harris
pushed a commit
that referenced
this pull request
May 27, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## svelte@5.55.10 ### Patch Changes - fix: unlink errored and otherwise finished batch ([#18264](#18264)) - perf: walk composedPath() directly in delegated event propagation ([#18268](#18268)) - fix: transfer effects when merging batches ([#18254](#18254)) - fix: allow `$derived(await ...)` in disconnected effect roots ([#18273](#18273)) - fix: remove temporary raw-text hydration markers ([#18269](#18269)) - fix: propagate async `@const` blockers through closure references so template expressions like `{(() => host)()}` correctly wait for the awaited value ([#18309](#18309)) - fix: properly unlink batches ([#18298](#18298)) - fix: settle discarded batch ([#18290](#18290)) - fix: declare `let:` directives before `{@const}` declarations on slotted elements ([#18271](#18271)) - fix: resume outro-ed branches if they were kept around ([#18291](#18291)) - fix: avoid waterfall-warning when async resolves to same value ([#18297](#18297)) - fix: correctly coordinate component-level effects inside async blocks ([#18260](#18260)) - fix: make unnecessary commit work less likely ([#18263](#18263)) - chore: add tag name to `a11y_click_events_have_key_events` warning ([#18272](#18272)) - fix: catch rejected promises while merging/committing ([#18266](#18266)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The propagation walk in
handle_event_propagationalready callsevent.composedPath()at the start to find the entry index, but then re-derives the same chain step-by-step viacurrent_target.assignedSlot || current_target.parentNode || .host. Three property reads per iteration is measurable on the hot event path.Walk the captured
patharray by index instead.Notes on behavior
composedPath()is the spec-compliant snapshot of the dispatch chain:hosttraversal (composed-path crosses shadow boundaries when appropriate).parentNodewalk would have stopped at a null parent).Performance
Measured in real Chromium on a click through a 30-deep tree with five delegated handlers: ~245k hz → ~277k hz (~+13%, ~−12% per-event time).
Test plan
🤖 Generated with Claude Code