mirror of https://github.com/sveltejs/svelte
perf: walk composedPath() directly in delegated event propagation (#18268)
## Summary 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. ## Notes on behavior `composedPath()` is the spec-compliant snapshot of the dispatch chain: - Same shadow-DOM crossings (slots and shadow roots are included for composed events). - Same `host` traversal (composed-path crosses shadow boundaries when appropriate). - Differs from the previous walk in one edge case: if a handler removes a parent mid-dispatch, the snapshot-based walk continues through the captured chain (matches native browser semantics — the previous `parentNode` walk 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 - [x] All 6006 runtime tests pass (runtime-runes + runtime-legacy + runtime-browser) - [x] Native shadow-DOM event tests (in runtime-browser) pass unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>pull/18271/head
parent
078f901f61
commit
04d408b29d
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
perf: walk composedPath() directly in delegated event propagation
|
||||
Loading…
Reference in new issue