Skip to content

perf: finish delegated-event and marker optimizations - #704

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-finish-remaining-event-marker-work
Aug 11, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-finish-remaining-event-marker-work

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Reuse one currentTarget accessor descriptor and getter across delegated
    handlers 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.
  • Reuse one stack-backed capture path across synchronous dispatches, with
    nested-frame restoration, native capture/bubble ordering, portal ancestry,
    propagation control, and controlled-input behavior preserved.
  • Extend both existing client-only single-root classifiers to exhaustive
    @switch trees. 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.
  • Add owning-package coverage for native descriptors, reentrant dispatch,
    public DOM boundaries, state/sibling identity, direct and nested case-local
    shadowing, and adoption of original server-rendered elements.
  • Add a self-contained production event work gate to the unified benchmark
    runner and strengthen the existing navigation work gate with exact visible-DOM
    controls and comment ceilings. Document the new marker phase and add an
    octane patch changeset.

Same-source production measurements

Existing workload Before After Preserved contract
128 events: distinct currentTarget descriptors 256 1 Exactly 256 accessor installations
128 events: distinct accessor getters 256 1 Native event identity and handler-local currentTarget
128 events: distinct delegated capture paths 128 1 Native/framework capture, bubbling, and 128 controlled outputs
1,024-leaf switch navigation: comment nodes 4,093 1 Exactly 2,052 elements and 1,025 text nodes
32-leaf nested switch navigation: comment nodes 126 2 Exactly 70 elements and 33 text nodes; shell/outlet identity

The 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.
  • Focused compiler, event, portal, control-flow, SSR, streaming, hydration,
    transition, conformance, and differential coverage — 162 files / 2,822 tests
    passed
    .
  • Existing real-Chromium deferred-event replay, Suspense/hydration, and Vite
    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-work allocation
    target passed.
  • Production SPA precise-work/census gate — both current-runtime Octane
    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.
  • Exhaustive 35-case conservative compiler proof matrix, frozen parsed
    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 removal is limited to proven client-created single-root components;
    marker ownership, streaming protocol, SSR bytes, and hydration adoption are
    unchanged. Incomplete, multi-root, and shadowed switch arms stay anchored.
  • Event measurements demonstrate deterministic allocation reductions rather than
    an unsupported latency claim. The small production bundle-size increases are
    disclosed above.

Refs #673.

Provenance

  • An agent produced this diff (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 currentTarget property 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/@else to exhaustive @switch with 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 Node is rewritten to @switch/@default so the proof applies at scale; work.mjs adds DOM element/text/comment ceilings (deep route 1 comment, nested 2 for TSRX). A separate event-delegation/work.mjs gate (wired into bench.mjs) asserts one descriptor, one getter, and one capture path over 128 production InputEvents, with an optional form onInputCapture hook 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.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 11, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review August 11, 2026 00:04
@domgan-oai
domgan-oai merged commit d2c9e1c into octanejs:main Aug 11, 2026
53 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