Skip to content

perf: skip stable hookful child call sites - #685

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-skip-stable-hookful-child-call-sites
Aug 10, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-skip-stable-hookful-child-call-sites

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Skip proven-stable child component call sites when a hook-owning TSRX component updates its own state.
  • Preserve independently scheduled descendants and observable module-setter publication across multiple roots.
  • Tighten production-browser work gates so unchanged descendant chains perform no component-slot dispatch.

Refs #673

Why

The existing same-module memoization proof treated any hookful descendant as unsafe. Consequently, updating one counter in a 100-component chain rerendered additional blocks and traversed up to 91 otherwise unchanged child slots even though the DOM required only one text update.

Module-level setter publication prevents a simple purity shortcut: another mounted root can own the same publication target, so an unchanged-props bailout must detect when that owner changed and rerun the original subtree.

Changes

  • Add a narrow, production-only same-module proof for real useState calls, simple immutable initializers, ordinary props, synchronous component trees, and uniquely written private setter bindings.
  • Propagate deduplicated setter-publication witnesses through proven descendants and snapshot them after the original child render, preserving multi-root setter ownership.
  • Cache the existing lightweight or full component-slot call directly without adding component boundaries, changing runtime representations, or introducing runtime helpers.
  • Decline unknown hooks, effects, context consumers, Suspense, custom comparators, keys, spreads, getters, proxy/property writes, mutable imported values, and other unproven shapes.
  • Add behavior coverage for pure hookful children, independent child state, external stores, context, effects, Suspense retries, custom comparators, refs, key changes, multi-root setter ownership, observable proxy writes, and SSR hydration.
  • Document the updated TSRX work contract and retain the unchanged JSX chain as an independent control.

Performance

Production-browser operation Block renders before → after Child-slot calls before → after DOM text writes
Shallow state update 10 → 1 91 → 0 1
Middle state update 5 → 1 41 → 0 1
Deep state update 1 → 1 1 → 0 1
Ten-state batched update 10 → 10 91 → 0 10

The paired minified production sweep improved from approximately 0.020 ms to 0.004 ms (5×), with both batch orders improving from 0.008 ms to 0.004 ms (2×). Sub-millisecond timing is quantized, so deterministic work counts are the acceptance signal. Mount retains exactly 19 blocks, 18 full slots, and 82 lightweight slots; teardown, JSX output/work, and the fixed 16-file compiler corpus remain unchanged.

Validation

  • pnpm --config.verify-deps-before-run=false sync
  • pnpm --config.verify-deps-before-run=false format:files:check on all changed files.
  • pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run typecheck — full workspace TypeScript body; unrelated optional pretypecheck disabled.
  • pnpm --config.verify-deps-before-run=false exec vitest run --project octane --project octane-prod --silent=passed-only — 804 files / 11,699 tests passed.
  • Focused compiler, immutable-AST, source-map, universal-renderer, SSR, hydration, context, transition, and Suspense suites — 70 files / 1,701 tests passed.
  • Production Chromium precise-call gates for both TSRX and unchanged JSX, including mount, shallow/middle/deep updates, batching, exact DOM writes, and teardown.
  • Same-policy paired minified Chromium timing, fixed compiler-output corpus, production bundle comparisons, and alternating compiler-throughput measurements.
  • Adversarial hook/publication classifier matrix — 26 accepted/rejected shapes passed.

Risk / follow-ups

  • New work is limited to compiler-proven, synchronous state-only subtrees; unproven hooks and observable side effects preserve existing component entry behavior.
  • The optimized benchmark bundle grows by approximately 476 gzip bytes; unrelated JSX output and the fixed compiler corpus remain byte-identical.
  • The exceptional 100-component fixture takes approximately 1.86 ms / 8.4% longer to compile; unaffected corpus compilation shows no measurable regression.
  • Paired mount timing changes by approximately 0.10 ms, while its block/slot allocation counts remain unchanged.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Compiler-only optimization with strict static proofs, but it changes render/skip semantics for hookful trees and relies on publication-witness correctness across roots and hydration—high impact if the proof is wrong, mitigated by extensive tests and unchanged behavior for unproven shapes.

Overview
Adds a production-only TSRX compiler path that memoizes same-module child component calls when a hook-owning parent re-renders with unchanged props, so deep chains no longer walk every descendant slot—only the stateful owner’s block runs and one text node updates.

The proof is intentionally narrow: components whose setup is only invariant useState plus optional one-time publication of setters into private module lets. classifyStableHookfulChildCalls marks eligible callees, propagates publication witnesses, and wires call sites through the existing auto-memo machinery—often via _$componentSlotLite—with post-render snapshots of setter bindings so multi-root publication stays correct.

Benchmark work.mjs gates for octane-tsrx now expect zero child slot dispatch on shallow/middle/deep/batched bumps; docs describe TSRX vs unchanged JSX cascade. auto-memo.test.ts adds broad regression coverage (child state, context, effects, stores, Suspense, refs/keys/memo, hydration, proxy/multi-root setters).

Reviewed by Cursor Bugbot for commit cdd13cd. 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 10, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review August 10, 2026 14:04
@domgan-oai
domgan-oai merged commit 97e65b9 into octanejs:main Aug 10, 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