Skip to content

perf: skip unused delegated capture fallback tasks - #1017

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/avoid-unused-capture-fallback-981
Sep 9, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/avoid-unused-capture-fallback-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Why

An authored capture handler makes finishCaptureDispatch schedule setTimeout(..., 0) for every trusted discrete event even when ordinary root bubbling closes the dispatch boundary. The timer then observes that bubble already ran and does no work.

Changes

  • Keep the fallback if a nested dispatch already queued a restore, or if input/change/click targets a native input, textarea, or select that could become controlled before its bubble is stopped. Other captured discrete events skip it.
  • Extend the existing event-delegation production gate with 16 trusted button clicks, native/framework capture and bubble order, event identity, and zero-delay timer counts. The same gate measured 16 tasks for 16 clicks on the unmodified runtime and 0 for 16 on this head, with all handler and existing input/portal/media controls passing.
  • Check nested restore and late control arming in development and production tests; each test was observed failing under a deliberately broken guard.

Validation

  • pnpm format:check (scoped pnpm format:files:check passed for all changed files)
  • pnpm typecheck
  • pnpm test (current-head CI will run the full suite)
  • targeted tests: discrete-dispatch-commit-timing.test.ts in octane and octane-prod (28/28), adjacent capture/dedup/controlled-restore suites in both modes (34/34), real Chromium event-boundaries.test.ts (28/28)
  • node benchmarks/event-delegation/work.mjs (production Chromium, all deterministic work gates passed)
  • pnpm sync, staged git diff --check

Risk / follow-ups

Captured form-control edit events retain the conservative fallback even when the target was uncontrolled at capture, because a native listener can arm it before stopping propagation. No change to native event routing or the separate signal event batch fallback.

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
Changes discrete-event dispatch-boundary timing for controlled form restores; behavior is narrowed with conservative form-control guards but still affects core event delegation.

Overview
Stops scheduling no-op setTimeout(0) capture fallback tasks for ordinary bubbling discrete events when authored capture is registered but nothing needs a post-dispatch controlled restore.

finishCaptureDispatch now returns early unless a restore is already queued from a nested dispatch, or the event is a restore-capable type (input/change/click) whose target is input, textarea, or select (so a native listener can still arm control and stop propagation before bubble). Clicks that complete delegation without that work no longer enqueue a timer that only discovers the bubble already ran.

Validation added: a Chromium work gate runs 16 trusted button clicks with capture/bubble order checks and asserts zero zero-delay timers during each click’s delivery (baseline was 16). Two dispatch-commit tests cover nested input restore when an outer click stops bubbling, and restore when an input becomes controlled after capture via a native target listener.

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

@github-actions github-actions Bot added the agent-authored Diff or issue body substantially produced by an AI agent label Sep 9, 2026
@github-actions github-actions Bot added the perf PR: performance work label Sep 9, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 14:41
@domgan-oai
domgan-oai merged commit 8a3da65 into octanejs:main Sep 9, 2026
50 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