Skip to content

perf: extend returned-JSX provider region caching - #687

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-extend-returned-jsx-region-caching
Aug 10, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-extend-returned-jsx-region-caching

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Extend returned-JSX provider-region caching from the completed wall-B descriptor-array shape to compiler-proven private mapped child components.
  • Reuse the original child descriptor only when the provider owns its scope, the mapped array has already passed Octane's native-array proof, component dependencies remain stable, and mapped children have safe default memo boundaries.
  • Preserve ordinary rendering for custom or overridden array methods, sparse/indexed-accessor arrays, custom species, inherited defaultProps, unmemoized child effects, fake providers, and server-rendered DOM adoption.
  • Tighten the existing production Chromium memo-wall work gates and document the new wall-A behavior; include an octane patch changeset.

Why

Merged PR #684 eliminated redundant returned-JSX wall-B reconciliation, but unchanged wall-A updates still entered their RowsA component and created avoidable wrapper descriptors. This follow-up removes that remaining work without changing authored benchmark fixtures or the public returned-JSX descriptor ABI.

Production Chromium operation RowsA executions Element descriptors Required visible work
Unchanged wall A 1 → 0 3 → 1 Unchanged rows and DOM
Context-only wall A 1 → 0 1,003 → 1,001 Exactly 1,000 updated context leaves
Changed wall A 1 → 1 8 → 8 Exactly one changed row, inner component, and leaf

Paired minified production measurements improved unchanged wall A from 0.001440 ms to 0.001032 ms (~28%) and context-only wall A from 0.620 ms to 0.582 ms (~6%); mount and changed-row timings remained stable. The affected benchmark bundle increased by 125 gzip bytes. The fixed 16-file code-generation corpus and unrelated production bundles remained byte-identical.

Changes

  • Add a conservative same-module compiler proof for private single-return mapped components and retain their descriptors inside genuine provider scopes using existing tail-owned memo slots.
  • Add an internal constant-time native-array reuse guard backed by the existing array-classification WeakMap; check live map/constructor/species/default-prop boundaries without invoking observable getters.
  • Preserve context ownership, imported memo witnesses, and immutable parser AST/source-map behavior.
  • Add public-behavior regressions for context, independent state, refs, effects, keyed updates, custom maps/proxies/species, inherited defaults, fake providers, and SSR hydration.
  • Require zero wall-A wrapper executions and reduced descriptor ceilings while retaining exact changed-item, context-leaf, wall-B, mount, and TSRX controls.

Validation

  • pnpm --config.verify-deps-before-run=false format:files:check .changeset/returned-jsx-provider-child-regions.md benchmarks/memo-wall/README.md benchmarks/memo-wall/work.mjs packages/octane/src/compiler/compile.js packages/octane/src/index.ts packages/octane/src/runtime.ts packages/octane/tests/auto-memo.test.ts
  • ./node_modules/.bin/vitest run --project octane --project octane-prod --silent=passed-only — 804 files, 11,725 tests passed.
  • Broad affected compiler, frozen-AST, source-map, SSR, hydration, universal, context, memo, Suspense, and transition coverage — 74 files, 1,821 tests passed.
  • Both returned-JSX and TSRX production Chromium memo-wall work gates, with exact DOM, row, context, and changed-item controls.
  • Paired minified production timing, compiler-throughput sampling, fixed code-generation corpus, and unrelated production-bundle tree-shaking checks.
  • pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run typecheck — complete workspace, bindings, packages, website, examples, and benchmarks passed.
  • pnpm --config.verify-deps-before-run=false exec vitest run packages/octane/tests/browser/suspense-hydration/suspense-hydration.test.ts --project octane-events-browser --silent=passed-only — 11 real-Chromium hydration tests passed.
  • pnpm --config.verify-deps-before-run=false sync — generated files and agent rules remain synchronized; no additional tracked changes.

Risk / follow-ups

  • The optimization is limited to compiler-owned private components, previously classified dense native arrays, default memo boundaries, and the existing immutable-array-snapshot contract. All other shapes retain their original descriptor/render behavior.
  • The benchmark-specific compiled application gained 125 gzip bytes; unrelated static and Suspense production bundles and the fixed compiler corpus did not change.

Refs #673.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches compiler auto-memo lowering and runtime reconciliation for context providers; optimization is gated conservatively but incorrect reuse could skip updates or break observable array/component semantics.

Overview
Returned-JSX provider regions can now cache and reuse a private child component that only returns a host with a keyed props.*.map(...) list—not just the existing static host + precomputed descriptor-array shape.

The compiler adds collectPrivateMappedProviderComponents: it proves module-local returned-JSX components used solely as <Context.Provider><Rows items={items} /></Context.Provider> children, with conservative checks (no escapes, safe memo boundaries, genuine provider scope). autoMemoReturnedProviderChild emits memo slots that call compilerCacheMappedArray instead of rescanning rows via compilerCacheArray, including capture/witness dependencies for imported memo components.

compilerCacheMappedArray (new runtime ABI export) reuses eligibility from the existing native-array WeakMap and declines custom maps, accessors, species, and observable defaultProps without triggering new getter reads.

memo-wall work gates and README now expect zero RowsA executions and fewer wrapper createElement calls on unchanged returned-JSX wall A; extensive auto-memo tests cover context, state, keys, effects, hydration, proxies, and fake providers.

Reviewed by Cursor Bugbot for commit 674e757. 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:55
@domgan-oai
domgan-oai merged commit 39b3e19 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