Skip to content

perf: index hoisted client capture values - #992

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/index-client-extra-981
Sep 8, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/index-client-extra-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Load hoisted client template helpers' captured values by index from their existing __extra array.
  • Bind only names used by each helper while retaining their positions in the shared item/empty or branch tuple.

Why

The compiler currently emits array destructuring on every keyed item and control-flow arm invocation. Even an elision-only arm requests an iterator and advances it before optimized JIT tiers can remove that work. The runtime already supplies a regular array, and another compiler fast path reads it by index.

Changes

  • Replace the client hoistBodyHelper destructuring AST with direct indexed bindings for each helper's own captures. Keep union-only names unbound so local shadowing remains valid, and preserve the existing tuple indices, including special keyed-item ordering.
  • Update the two client codegen expectations and add a public nested keyed/conditional fixture covering sparse captures, a shadowed local, reorder identity, branch changes, @empty, and refill.
  • Add an octane patch changeset. The separate server capture path is unchanged.

Validation

  • Source-only compilation of the nested fixture through the cached compiler, followed by an in-memory conversion to indexed loads, passes mount/reorder/identity/empty checks. A deliberately wrong outer item index renders the wrong captured value and turns the same assertions red. The pinned current compiler and test suite await CI.
  • Node 26/V8 14.6 helper-shape probe: three-capture destructuring 203 → 29 bytecode bytes with iterator work replaced by three keyed loads; elision-only destructuring 161 → 3 bytecode bytes when the unused binding is omitted.
  • Same-environment Chromium 149, four warmups and eight mirrored ABBA cycles: 10,000 fresh helper calls with three captures 0.30 → 0.10 ms, sparse captures 0.20 → 0.10 ms, elision-only 0.25 → timer floor. A source-only keyed DOM mount proxy was neutral at 10,000 rows (18.45 → 18.45 ms). Exact checksums, DOM order, keyed survivor identity, clicks, and unmount were verified. These synthetic timings do not establish a compiled application speedup.
  • Cached Prettier check for changed JS/TS/changeset, node --check for the compiler, and git diff --check.
  • Current-head CI passed all 26 jobs at 0dd952979b441b10bd0e2ea8c5779c11583770ec. Both changed test files ran and passed in octane and octane-prod (nested directives: 3 tests per project; value-position directives: 85 per project). Typecheck and browser integration passed.
  • Pinned codegen-size run on this PR head produced its artifact and tested all 28 applicable guards. Two deterministic guards failed: compiled/source gzip 27898 / 25698 = 1.0856 versus 1.06, and CSS-module client minified 2341 / 2743 = 0.8534 versus 0.84. An identical-workflow baseline run on merged main failed the same two guards; this PR increased aggregate compiled bytes by +340 raw, +109 minified, and +75 gzip versus main (27823 → 27898 gzip). The CSS-module sentinel was byte-identical. A separate, unshipped compact-binding trial recovered only 15 of those gzip bytes; the shipped code is the tested PR head. The full quick Bench run was canceled after more than 60 minutes. It uploaded partial results for 78/92 suites; suite 79 (tsrx-hydrate-module-slicing) logged no progress for about 26 minutes, so no full ratio summary exists. Several earlier suites had unrelated correctness or size failures. The paired targeted runs above provide the deterministic codegen-size evidence. Fork-only workflow setup changes for runner selection and local benchmark links did not change package source, benchmark scripts, or the lockfile.
  • The pinned @tsrx/[email protected] dependency is unavailable locally; frozen install and pnpm sync could not complete through the configured registry. The automatic approval review rejected a direct public-registry fetch as a bypass of that registry. CI validated the pinned compiler, compiled output, and public fixture behavior.

Risk / follow-ups

The array ABI remains internal and always receives arrays from the runtime. A user-modified Array.prototype[Symbol.iterator] would no longer be invoked by these generated capture reads. Isolated fully populated helpers can gain minified bytes while sparse/elision-only helpers shrink, so the pinned codegen-size and benchmark ratio gates matter. No broad runtime speed claim is made from the synthetic proxy.

Refs #981. Follows merged #991.

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 hot-path client compiler output for every hoisted template arm, but the __extra ABI and runtime contract are unchanged and behavior is locked down with new fixture coverage.

Overview
Client codegen for module-scoped construct helpers (@if/@else, @for item/@empty, etc.) no longer opens __extra with array destructuring. Each helper now emits const name = __extra[i] only for captures that arm actually uses, keeping the same union tuple indices (including keyed @for reordering) so sparse arms and local shadowing stay correct.

Server capture lowering is unchanged. Tests now expect indexed client bindings, and SparseCaptureFeed plus a mount test cover sparse nested arms, keyed reorder/identity, branch flips, @empty, and refill.

Patch changeset for octane.

Reviewed by Cursor Bugbot for commit 0dd9529. 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 8, 2026 13:00
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 8, 2026
@domgan-oai
domgan-oai merged commit faae10e into octanejs:main Sep 8, 2026
50 of 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