Repository navigation
perf: finish delegated-event and marker optimizations - #704
Merged
domgan-oai merged 1 commit intoAug 11, 2026
Merged
domgan-oai merged 1 commit into
domgan-oai merged 1 commit into
Conversation
domgan-oai
marked this pull request as ready for review
August 11, 2026 00:04
95 tasks done
6 of 7 tasks
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
Finish the remaining P3 work in #673: reduce native delegated-event allocations
without changing dispatch semantics, and extend the existing ownership-safe
component marker proof to exhaustive switch-root components.
Changes
currentTargetaccessor descriptor and getter across delegatedhandlers while keeping the active target private to each native event.
Reinstall the accessor for every handler, including after consumer
replacement/deletion, and restore native event behavior after dispatch.
nested-frame restoration, native capture/bubble ordering, portal ancestry,
propagation control, and controlled-input behavior preserved.
@switchtrees. Require@default, exactly one qualifying root per arm,proven same-module component identities, and conservative rejection of
switch-owned lexical shadows, empty cases, fragments, and multiple roots.
public DOM boundaries, state/sibling identity, direct and nested case-local
shadowing, and adoption of original server-rendered elements.
runner and strengthen the existing navigation work gate with exact visible-DOM
controls and comment ceilings. Document the new marker phase and add an
octanepatch changeset.Same-source production measurements
currentTargetdescriptorscurrentTargetThe unchanged JSX navigation control retains zero comments. Paired production
navigation medians moved from approximately 2.0–2.1 ms to 1.5–1.7 ms; event
wall-clock samples were noisy, so no event latency improvement is claimed.
The fixed 16-file compiler corpus remains byte-identical at 153,572 raw /
75,799 minified / 26,823 gzip bytes. Server output remains byte-identical.
The eligible event fixture grows by 35 gzip bytes and the equivalent switch
fixture grows by 68 gzip bytes; generic production root, hydration,
deferred-hydration, and Suspense bundles grow by 23–51 gzip bytes.
Validation
./node_modules/.bin/vitest run --project octane --project octane-prod --silent=passed-only— 806 files / 12,014 tests passed.
transition, conformance, and differential coverage — 162 files / 2,822 tests
passed.
production SSR/deferred-hydration suites — 30 browser tests passed.
pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run typecheck— full workspace, integrations, website, 17 examples, and SPA benchmark.
node benchmarks/bench.mjs --quick --results-dir=/private/tmp/octane-p3-event-unified event-delegation— all six framework targets plus the enforced
octane-tsrx-workallocationtarget passed.
dialects, all existing navigation/deoptimization controls, retained shell and
outlet identity, and hardened deep/nested comment ceilings.
node benchmarks/bench.mjs --quick --results-dir=/private/tmp/octane-p3-compiler-bench codegen-size compiler-throughput bundle-size bundle-reachability— compiler corpus, six-framework throughput, normalized production bundles,
and public-import feature tree-shaking passed.
AST/source origins, both-mode byte-identical server output, same-source
production before/after controls, and scoped Prettier /
git diff --check.pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run sync— all generated artifacts already current.
Risk / follow-ups
marker ownership, streaming protocol, SSR bytes, and hydration adoption are
unchanged. Incomplete, multi-root, and shadowed switch arms stay anchored.
an unsupported latency claim. The small production bundle-size increases are
disclosed above.
Refs #673.
Provenance
agent-authored)Note
Medium Risk
Changes delegated event dispatch and compiler elision proofs on hot paths, but behavior is heavily pinned by new gates and expanded tests; SSR/hydration and incomplete switch shapes stay conservative.
Overview
Finishes delegated-event and comment-marker work from the existing optimization track: less allocation during native dispatch and fewer client-only component markers when the compiler can prove a safe shape.
Delegated events now store the active handler element on a per-event symbol and reinstall one shared
currentTargetproperty descriptor for every handler (including after consumers replace or delete the accessor). Capture phase walks reuse a module-level stack with nested-dispatch frame restore instead of allocating a fresh path array per event. React-parity semantics for capture/bubble order,currentTarget, nested dispatch, and controlled inputs are unchanged; new unit coverage exercises reentrancy and accessor identity.Compiler (M8) widens the existing transitive single-root and anchorless-host proofs from exhaustive
@if/@elseto exhaustive@switchwith an explicit@default, one qualifying root per case, and conservative rejection of case-local bindings, fragments, and unproven callees. Qualifying components keep using the existing$$singleRoot/ anchorless slot machinery—client mount only; SSR bytes and hydration adoption are untouched.Benchmarks and fixtures: the spa-navigation TSRX tree’s recursive
Nodeis rewritten to@switch/@defaultso the proof applies at scale;work.mjsadds DOM element/text/comment ceilings (deep route 1 comment, nested 2 for TSRX). A separateevent-delegation/work.mjsgate (wired intobench.mjs) asserts one descriptor, one getter, and one capture path over 128 productionInputEvents, with an optional formonInputCapturehook on the runtime-stress app for framework capture checks.Reviewed by Cursor Bugbot for commit 5e05891. Bugbot is set up for automated code reviews on this repo. Configure here.