Skip to content

perf: reuse bounded keyed-reorder scratch storage - #630

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/bounded-keyed-reorder-scratch
Aug 7, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/bounded-keyed-reorder-scratch

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Part of #611 (phase 5).

  • Reuse bounded numeric source and LIS-predecessor buffers only after keyed reconciliation reaches its general middle-section path.
  • Lease source buffers exclusively across survivor rendering and release them on every return, error, suspension, or transition rollback; synchronous LIS work reuses its own buffer.
  • Retain at most two 16,384-entry Int32Array buffers (128 KiB total), discard oversized buffers, and never retain keys, item objects, blocks, or DOM nodes.
  • Add consumer-visible mixed parent/child reorder, hydration, error, Suspense, and transition regressions. Deliberately removing exclusive leasing makes the new nested-order test fail; restoring it makes the same test pass.
  • Add a post-timing production benchmark gate for warmed allocation-free reorders, stable survivor identity, ordinary inserts, oversized-list disposal, and garbage-collected retained backing storage.
Production measurement Upstream This change
Warm 1,000-row general reorder 2 typed arrays / 8,000 B 0
Warm 10,000-row general reorder 2 typed arrays / 80,000 B 0
5,000 warmed 1,000-row rotations 40,000,000 B typed scratch 0
Retained scratch after 10,000-row and oversized reorders 0 80,000 B; maximum 131,072 B
TSRX / JSX production gzip increase — +71 B / +77 B

A balanced 64-pair, two-epoch 10,000-row reversal comparison preserved exactly 9,999 DOM moves: persistent-list medians were 11.375 ms upstream versus 11.3625 ms after this change; fresh-list medians were 6.3625 ms versus 6.25 ms. A 5,000-rotation Chrome trace showed transient ArrayBuffer backing growth of 96–560 KB upstream versus 15 B after reuse; median minor-GC counts were unchanged, so this change does not claim fewer collections.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted tests:
    • Faithful repository-root Octane development project: 401 files / 5,948 tests passed.
    • Faithful repository-root Octane production project: 365 files / 4,887 tests passed.
    • Both projects preserve the root renderer registry, frozen-AST/location checks, cleanup, and existing excludes. Only external-hook-slot.test.ts and register-hook.test.ts were additionally excluded because this safely filtered offline workspace cannot install their optional binding dependencies.
    • ./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json
    • ./node_modules/.bin/tsgo --noEmit -p packages/octane/typetests/tsconfig.json
    • pnpm typecheck:files packages/octane/src/runtime.ts
    • Official JSX/TSRX canonical production benchmark: previous list-mounting, DOM, selection, and production-call gates passed.
    • Official JSX/TSRX/React keyed-reorder benchmark: all identity and bounded-scratch gates passed; committed TSRX/React rotation ratio 0.331 <= 0.6.
    • Newly merged upstream TodoMVC conditional-row guard: Octane and React both perform exactly 25 row-class writes; ratio 1 <= 2.
    • Permanent production gate verified red against unchanged upstream and green for both optimized Octane dialects.
    • pnpm sync
    • node scripts/check-changesets.js

Full workspace pnpm typecheck and pnpm test remain unavailable because the configured package registry cannot supply uncached optional Preact/Ripple binding dependencies; no registry override or substitute package source was used.

Risk / follow-ups

  • This is shared keyed-reconciler code, so all client bundles include the measured +71/+77 gzip-byte increase.
  • Numeric scratch is intentionally bounded and retained between reconciliations; oversized lists allocate disposable buffers and cannot grow retained capacity beyond 128 KiB.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches shared reconcileKeyed / LIS paths used by all keyed lists; incorrect buffer leasing could corrupt nested reorders or retain unbounded memory, though new gates and tests target those failure modes.

Overview
Keyed list reconciliation in reconcileKeyed no longer allocates fresh Int32Array scratch on every middle-section diff. It leases a reusable sources buffer (cleared from the module cache while survivor bodies run, then returned in a finally block) and caches a separate LIS predecessor buffer, keeping at most two 16,384-entry arrays (~128 KiB) and dropping oversized buffers instead of retaining them.

The keyed-reorder benchmark adds a post-timing scratch-storage gate for Octane TSRX/JSX: an Int32Array constructor trap checks that warmed reorders, append-only inserts, and shrink-back behavior stay allocation-free where expected, while very large lists may allocate disposable scratch without polluting the reusable pool; retained backing storage after GC must stay ≤128 KiB.

Regression coverage adds nested parent/child keyed reorder fixtures and tests (DOM identity, hydration, error boundaries, Suspense, and transitions) to guard exclusive buffer leasing when lists re-enter during rendering.

Reviewed by Cursor Bugbot for commit 8044a11. 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 7, 2026
@trueadm
trueadm marked this pull request as ready for review August 7, 2026 21:38
@domgan-oai
domgan-oai merged commit 10011bb into octanejs:main Aug 7, 2026
53 checks passed
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
leonidaz pushed a commit that referenced this pull request Aug 9, 2026
* feat(gsap): add Octane useGSAP binding

* fix(ci): allow current Octane release

* chore(evals): refresh user app corpus manifest

* docs: list GSAP in agent binding guide

* fix(gsap): align review edge cases

* test: register GSAP manual hook slots

* fix(gsap): keep mount cleanup hook stable

* fix(gsap): preserve positional null dependencies (#423)

* fix(evals): drop duplicate user-apps manifest rows

The train manifest accidentally appended a second copy of every taskId with stale package pins, which breaks dataset validation.

Co-authored-by: Cursor <[email protected]>

* chore(ci): refresh react-parity evidence after main merge

Regenerate lockfile hashes and inventory for gsap.

* perf: reuse bounded keyed-reorder scratch storage (#630)

* chore(ci): refresh react-parity evidence after main merge

Regenerate lockfile hashes and inventory for gsap.

* chore(changeset): drop stale merge-resurrected release entries

Remove octane and mcp-server changesets that already shipped on main and
would duplicate patch bumps in this GSAP binding PR.

Co-authored-by: Cursor <[email protected]>

* fix(gsap): drop unrelated merge-residue release-age excludes

Keep only the mainline [email protected] exclude; the broader package list was
merge residue and weakened the workspace gate without belonging to GSAP.

Co-authored-by: Cursor <[email protected]>

* test(gsap): register React/Octane parity evidence

Upstream @gsap/react ships no runtime suite, so add a repo-authored adapted
lane, differential project against the pinned binding, type lanes, and
audit/react-parity.json for react-parity:check discovery.

Co-authored-by: Cursor <[email protected]>

* fix(gsap): address parity review on unpaired suite and deferred cleanup

Move Octane-only lifecycle cases out of react-parity ownership, require only
differential evidence when upstream runtime tests are absent, and assert
unmount cleanup through a teardown-surviving side channel.

Co-authored-by: Cursor <[email protected]>

* chore(ci): refresh inventory and parity hashes after main merge

Restore @octanejs/gsap in the generated package inventory and regenerate
react-parity lockfile integrity plus the user-apps corpus pins.

Co-authored-by: Cursor <[email protected]>

* chore(ci): refresh inventory and eval manifests after main merge

Co-authored-by: Cursor <[email protected]>

* fix(ci): refresh vitest.config.js react-parity digests

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: domgan-oai <[email protected]>
leonidaz pushed a commit that referenced this pull request Aug 10, 2026
* docs(packaging): plan CommonJS package conditions

* feat(packaging): add CommonJS graph builder

* fix(packaging): parse CommonJS graphs with esbuild

* feat(octane): publish CommonJS runtime entries

* feat(bindings): publish CommonJS runtime graphs

* test(packaging): exercise packed CommonJS consumers

* chore(release): record CommonJS package conditions

* test(packaging): run CommonJS tarball canary

* test(packaging): compare ESM and CommonJS parity

* fix(review): guard CommonJS output deletion

* fix(review): reject lossy CommonJS transforms

* feat(packaging): compile TSRX CommonJS graphs

* perf(packaging): reuse TSRX compilation work

* feat(packages): support callable CommonJS defaults

* fix(packages): recognize TSRX CommonJS roots

* perf: speed up server-rendered HTML escaping (#629)

* perf: skip unchanged conditional keyed rows (#628)

* perf: skip unchanged conditional keyed rows

* fix: exclude Activity boundaries from keyed row memoization

* fix(ci): prevent usehooks hydration timeout

* fix(ci): refresh React parity evidence hashes

* perf: reuse bounded keyed-reorder scratch storage (#630)

* perf: add minimal-import bundle reachability budgets (#631)

* perf: add minimal-import bundle reachability budgets

* fix: register reachability benchmark with MCP server

* fix: preserve side-effect-only bootstrap entrypoints (#633)

* perf: cache stable renderable regions and prune sync warming (#634)

* perf: cache stable renderable regions and prune sync warming

* fix: preserve uppercase-prefixed custom hook state

* fix(benchmarks): remove js-framework DOM node metrics (#636)

* fix(bindings): classify production bundle side effects (#637)

* feat: enable React Compiler across framework benchmarks (#639)

* perf: reduce core runtime and compiled application bundles (#638)

* Version Packages (#601)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(commonjs): fail closed on authored .tsrx modules

Refuse compiling .tsrx into CommonJS packaging output so published packages keep source for consumers to compile.

Co-authored-by: Cursor <[email protected]>

* fix(commonjs): restore published require export conditions

Re-apply the CommonJS require maps for octane and the binding packages after the main merge dropped them.

Co-authored-by: Cursor <[email protected]>

* fix(commonjs): order require before default and wire binding prepack

Put import/require ahead of default in octane publishConfig.exports so Node does not always pick the ESM graph, and run build:cjs from prepack for the binding packages that advertise dist/cjs.

Co-authored-by: Cursor <[email protected]>

* fix(compiler): discover source packages without a CommonJS build

require.resolve failed on prepack-only dist/cjs entries in CI, so Vite
source discovery skipped Base UI and nested bindings. Fall back to the
installed package manifest when the require target is missing.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: domgan-oai <[email protected]>
Co-authored-by: Dominic Gannaway <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Cursor <[email protected]>
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