Skip to content

perf: avoid nested universal hook slot arrays - #1026

Merged
domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/universal-hook-slot-spread-981
Sep 10, 2026
Merged

domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/universal-hook-slot-spread-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Resolve nested universal hook slots by reading the captured stack depth directly, removing the temporary array spread on every hook call. Universal and native renderers share this path.
  • Preserve the existing segment encoding, repeated coercion, implicit slot numbering, and Symbol.for behavior.
  • Add a public-root regression for sibling state/ref identity, reordered hooks, reentrant slot coercion, failed render, retry, and teardown, plus a production-bundle allocation guard.

Why

Issue #981 identified temporary arrays in the universal hook-slot path. The direct-hook fast path is unchanged; nested hooks previously evaluated one array literal per lookup.

Validation

  • pnpm format:check (scoped pnpm format:files:check passed for all changed files)
  • pnpm typecheck
  • pnpm test (not run as one local command; the full sharded suite passed in current-head CI)
  • MCP benchmark manifest test: 15/15 passed after reproducing and fixing the CI mismatch.
  • Current-head CI: 26/26 jobs successful at 294f6b0cf.
  • Universal tests: 36 files, 722 tests passed; the new regression failed under a deliberate ancestor-slot break and passed again after restoration.
  • node benchmarks/bench.mjs --quick universal-hook-slot --ratios (its zero-array assertion passed; no ratio guards selected for this new suite).
  • Paired benchmark against 621147d01: at 128 nested owners, 1,024 → 0 resolver array events on mount, changed-prop update, state update, and keyed reorder; total runtime array events fell by exactly 1,024 in each phase. Direct hooks, setup, and teardown were unchanged, with matching output and hook-call counts.

Risk / follow-ups

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 the production universal hook-slot resolver on every nested hook call; behavior is guarded by new tests and a zero-array benchmark gate.

Overview
resolveHookSlot no longer builds [...UNIVERSAL_SLOT_STACK, own] on nested lookups; it walks the captured stack depth with an indexed loop and the same string/Symbol.for encoding, leaving the direct (empty-stack) fast path unchanged.

A new universal-hook-slot Node benchmark (wired into bench.mjs, docs, and the MCP suite list) production-bundles the runtime, instruments resolveHookSlot, and fails unless resolver array-creation events are zero across mount, prop/state updates, reorder, and unmount for direct vs doubly nested withSlot workloads.

universal-manual-hook-context.test.ts adds a regression for nested sibling hook state/refs through reorder, reentrant slot coercion, a failed render, retry, and teardown.

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

@domgan-oai
domgan-oai marked this pull request as ready for review September 10, 2026 09:38
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 10, 2026
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