Skip to content

perf: skip unchanged returned JSX descriptor walls - #684

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-returned-jsx-wall-b-memoization
Aug 10, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-returned-jsx-wall-b-memoization

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Reuse unchanged, compiler-proven descriptor arrays in returned JSX without changing provider children, hydration ranges, or context semantics.
  • Identify real active context providers through scope ownership instead of observing user-defined properties or proxies.
  • Add independent wall-A/wall-B production-browser work gates and adversarial behavioral coverage.

Refs #673

Why

Returned JSX already cached wall B's derived descriptor array, but recreated its surrounding scoped host descriptor every render. Equal and context-only updates consequently performed 1,000 keyed survivor visits and 1,000 shallow memo comparisons even when the rows were unchanged.

Changes

  • Carry nonescaping auto-calculated array provenance through returned-JSX lowering.
  • Cache the original scoped host descriptor under its actual context provider while preserving public children, SSR output, and hydration identity.
  • Allocate compiler-only memo slots after shared client/server slots and inspect array eligibility only when a memo hit can skip reconciliation.
  • Keep unsafe accessors, nested arrays, fragments, deferred context reads, escaped mutable arrays, custom providers, and hostile provider getters on their original paths.
  • Make JSX precise-call coverage use the same unminified production-only work mode as TSRX and tighten both dialects' unchanged-wall expectations.

Performance

Workload Before After
JSX wall-B equal survivor visits 1,000 0
JSX wall-B equal memo comparisons 1,000 0
JSX wall-B equal update 0.1891 ms 0.0010 ms
JSX wall-B context update 0.8000 ms 0.6045 ms
JSX wall-B changed update 0.2580 ms 0.2560 ms

Equal updates are approximately 188× faster. Context updates still refresh exactly 1,000 leaves, changed updates still reconcile the changed row, and context-restamping remains zero. The eligible fixture grows by 237 gzip bytes; unrelated production bundles and the fixed 16-file codegen corpus are byte-identical.

Validation

  • pnpm sync
  • pnpm format:files:check on all eight changed files.
  • pnpm --config.enable-pre-post-scripts=false run typecheck — complete workspace TypeScript body; unrelated optional pretypecheck disabled.
  • pnpm exec vitest run --project octane --project octane-prod --silent=passed-only — 804 files / 11,681 tests passed.
  • Focused compiler, frozen-AST, source-map, universal-renderer, SSR, and hydration suites — 66 files / 1,571 tests passed.
  • Returned-JSX hydration and hostile/custom-provider regressions in development and production.
  • JSX and TSRX production Chromium memo-wall precise-call gates, including unchanged, context-only, changed-row, and wall-A controls.
  • Same-policy paired minified Chromium benchmarks and exact production bundle tree-shaking comparisons.
  • node benchmarks/codegen-size/run.mjs — fixed corpus unchanged.

Risk / follow-ups

  • Admission requires a compiler-proven, nonescaping descriptor array under the currently active context provider; unknown or unsafe shapes retain existing behavior.
  • Generated memo slots are client-only tail slots, preserving server/client hook-site identity.
  • Additive compiler-runtime helper is tree-shaken from applications without eligible returned-JSX sites.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Changes compiler lowering and provider child reconciliation for a gated optimization path; incorrect admission could skip updates or break context/hydration, though fallbacks and extensive behavioral gates limit blast radius.

Overview
Returned-JSX wall B no longer rebuilds and reconciles 1000 unchanged memo(Row) descriptors on equal or context-only parent updates. The compiler now threads auto-calculated renderable-array provenance through returned-JSX lowering (setup statements only, not the return root) and, for a narrow <Context.Provider value={…}><host>{rows}</host></Context.Provider> shape, wraps the scoped provider’s readChildren in useMemo + compilerCacheArray when rows is a proven non-escaping calculation.

Eligibility is gated at runtime by compilerOwnsContextProvider, which checks whether the provider value is already in CURRENT_SCOPE.$$ctxValues without re-reading .Provider or user getters/proxies. Ineligible patterns (custom Provider components, escaped/mutated arrays, accessors, deferred use(), etc.) keep the old path.

Memo-wall docs and work.mjs now expect zero keyed survivors and zero shallowEqualProps for JSX wall-B equal/context ops (TSRX-aligned), with upper ceilings on wrapper createElement counts. JSX work builds can disable minification via MEMO_WALL_WORK=1 like TSRX. A large auto-memo.test.ts block covers descriptors, hydration, context, refs, effects, and hostile providers.

Reviewed by Cursor Bugbot for commit 7871550. 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 13:16
@trueadm
trueadm merged commit 8c29020 into octanejs:main Aug 10, 2026
53 checks passed
jonkwheeler added a commit to jonkwheeler/octane that referenced this pull request Aug 10, 2026
Restore autoMemo LocalHazards from main (dropped by earlier merges) while
keeping descriptorChildren bindings/lowering, and take octanejs#684 returned-JSX
wall-B memoization.

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.

2 participants