Skip to content

perf: avoid repeated delegated event paths - #1016

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/avoid-duplicate-composed-path-981
Sep 9, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/avoid-duplicate-composed-path-981

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Skip composedPath() in the root capture observer when one public root has no portals and no authored capture path is needed; retain the root epoch stamp.
  • Reuse a local native path across the capture and emulated bubble queues of a nonbubbling event. Separate native capture/bubble callbacks, nested roots, and portals still prepare their own paths.
  • Add behavioral regressions for synchronous nonbubbling capture updates and nested-root remounts, plus a production Chromium work gate with an isolated no-capture input form and a nonbubbling play event.

Addresses the delegated composedPath() finding in #981. Keep the issue open for its remaining checklist items.

Validation

  • pnpm typecheck
  • pnpm format:files:check on all changed files; pnpm sync generated no tracked changes
  • Targeted event/portal/focus/capture suites: 62/62 across development and production projects
  • node benchmarks/event-delegation/work.mjs in Chromium: no-authored-capture inputs 256 → 128 path calls for 128 events; nonbubbling play 3 → 1. Authored input capture remains 256/128 events, with portal, handler order, controlled output, and native propagation controls passing on both main and candidate.
  • node benchmarks/bench.mjs --quick event-delegation before and after: captured-input timing 14.4 ms → 8.4 ms in two-sample quick runs; other framework timings moved too, so no throughput gain is claimed.
  • pnpm test: attempted locally on Node 26; the long multi-project run reported unrelated timeouts and Node 26 localStorage failures, then exhausted its 4 GB V8 heap. Isolated Jotai utils passed 10/10 and compiler/Volar passed 26/26 on supported Node 22. The email preview watcher test fails identically with the unmodified main runtime on this host. Current-head CI on Node 24 is the full-suite gate.

Risk / follow-ups

  • The path remains local to one nonbubbling native listener; no Event path is retained across callbacks. A portal or multiple active roots still requires the eager composed path and ownership checks.
  • The usual captured-input timing fixture cannot measure the no-capture improvement. The deterministic work gate covers that path; wall-clock timings there were not collected.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches core delegated event propagation in the runtime; behavior is constrained to single-root/no-portal and path-reuse paths but incorrect path timing could break capture/bubble ordering or nested roots.

Overview
Reduces how often Octane calls Event.prototype.composedPath() during delegated event delivery, which was a hotspot for simple apps with one root and no portals.

In prepareDelegatedEvent, when there is a single delegation root and no portals, the root capture observer now only stamps the root epoch and returns without building a path; bubble handling can construct the path once after native target listeners run. For nonbubbling events that share one native capture callback, dispatchDelegated passes the same path into capture and emulated bubble (buildDelegatedPath) instead of calling composedPath() again. Multi-root, portal, and authored-capture cases still prepare paths eagerly when needed.

Benchmark and test coverage adds a separate event-work-no-capture production fixture (no authored input capture at module load), extends work.mjs to assert one composedPath per input on that path and one per nonbubbling play event with correct handler order, and adds regressions for capture-time remounts on play and nested-root bubbling after inner remount.

Reviewed by Cursor Bugbot for commit 937fc52. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 9, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 14:10
@domgan-oai
domgan-oai merged commit c6300cf into octanejs:main Sep 9, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant