Skip to content

perf: stabilize client block shapes across boundaries - #990

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/predeclare-block-expandos-981
Sep 8, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/predeclare-block-expandos-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Reserve nine optional BlockImpl fields at construction so ordinary, Suspense, Activity, and fetch-tree-warming blocks keep the same V8 object shape.
  • Preserve undefined defaults, existing assignments, and the previous order of all preexisting fields.

Why

After #989 removed redundant native class-field definitions, ordinary blocks still gained two fields on first render. Suspense, Activity, use(), and warm replay added more fields later, splitting the map at common Block read sites. A constructor-only shape probe on current main found 53 own fields before render, 55 afterward, and 58 on a Suspense boundary, with different V8 maps. This PR pays for fixed slots on every block while keeping feature handlers and caches lazy.

Changes

  • Add type-only field declarations and fixed-order undefined constructor assignments for the nine late Block fields.
  • Replace the stale Activity shape comment and add a client behavior regression covering visible updates, a hidden Suspense retry, asynchronous resolution, reveal, DOM identity, and authored display.
  • Add an octane patch changeset.

Validation

  • Public compiled fixture through a source-only JSDOM harness passes; deliberately omitting the Activity back-reference assignment makes the hidden fallback visibly unhide and fails the same assertion.
  • Node 26.4/V8 14.6 probe: 62 own fields on fresh, ordinary, Suspense, and Activity blocks; %HaveSameMap matches across modes and all objects retain fast properties.
  • Same-source esbuild 0.28.1 / Chromium 149 ABCCBA comparison on Apple M5 Max (three warmups, six paired cycles): 1,024 keyed rows under 16 actual boundaries, 12 visible updates, exact row order/text/DOM identity/unmount. Source-only Activity median 3.95 → 3.50 ms; resolved Suspense 4.05 → 3.45 ms. This is directional and does not time actual suspension/retry or the compiled Activity benchmark.
  • 1,000/10,000 keyed-row mount control: 1.10 → 1.00 ms / 8.40 → 8.30 ms; both differences overlap run variation. Retained heap is approximately +32 bytes per block (100,000 rendered blocks, repeated GC samples). Full-index bundle is +236 raw / +38 gzip / +102 Brotli bytes.
  • Cached Prettier on changed files, esbuild TypeScript parse, git diff --check, and source-only behavior/shape probes.
  • Current-head CI: all 26 jobs passed, including the new regression in octane and octane-prod, lint, typecheck, Chromium integration, parity, and provenance.
  • Pinned local Vitest/typecheck and pnpm sync could not start after the package registry returned 403 during the frozen install.

Risk / follow-ups

Every client Block carries nine additional enumerable internal fields, costing about 32 retained bytes. The source-only boundary timings are directional; a focused compiled Activity throughput comparison remains follow-up performance evidence. Code that reflects over private Block/Scope objects can observe the extra keys, though this is not a supported component contract.

Refs #981. Follows merged #989.

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 core client BlockImpl allocation in the renderer with a small per-block memory cost; behavior is covered by a new boundary regression test but the change affects all blocks.

Overview
Reserves nine optional boundary/render fields on every BlockImpl at construction (__warmEpisode, thenable/Suspense/try/Activity slots, warm cache, etc.) so ordinary renders, Suspense, Activity, and fetch-tree warming no longer grow the object shape on first use.

Runtime comments now describe this as intentional: __activitySlot stays on the common block shape instead of being treated as a rare expando. A new Vitest case exercises Activity + hidden Suspense retry—visible/hidden toggles, async resolve, reveal, DOM identity, and display styles—so boundary behavior stays correct with the unified shape. An octane patch changeset records the release note.

Reviewed by Cursor Bugbot for commit 8fd3c16. 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 11:10
@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 4d00715 into octanejs:main Sep 8, 2026
47 of 50 checks passed
domgan-oai pushed a commit that referenced this pull request Oct 7, 2026
…les (#1868)

* docs(skills): add perf-review and hot-path V8, DOM, and scheduling rules

Agent-written PRs now get one place that states the hot-path rules and one
skill that checks a diff against them.

- performance-audit gains three references grounded in runtime code:
  V8 shapes and allocation, DOM work without forced layout, and
  microtask/task scheduling (the #1864 megatask findings). It also gains
  an evidence table per kind of change and the local-load rule.
- New perf-review skill: classify the diff hot or cold, read the
  mechanical candidates, judge each dimension, and require evidence.
- scripts/perf-review-scan.mjs is the advisory scan behind it. Two
  invariants hold on main with zero hits: hot classes assign every
  declared field unconditionally in the constructor, and writes through
  Block/Scope receivers only target declared fields. On pre-#990 runtime
  the second finds all 13 shape-forking writes #990 fixed. Over the last
  150 source commits the line rules report 44 candidate lines in 11
  commits.
- octane-core-extend, core-engineering, and create-a-pr route hot-path
  diffs through perf-review; the root rule lists its trigger.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(scripts): let perf-review-scan --diff accept fields the diff declares

A pasted PR diff is scanned against the local checkout's runtime.ts. A PR
that correctly declares a new BlockImpl field would then get a false
hot-field-write for writing it, and the structural check would inspect the
checkout instead of the reviewed head. Fields declared in the diff now count
as known, and --diff leaves hot-class-shape to --head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(scripts): diff perf-review-scan --head from the target's fork point

Without --base, --head took the merge-base of the current checkout and main,
then a second merge-base with the target. A checkout older than the target's
fork point pulled unrelated main commits into the scanned diff. The base is
now the merge-base of the target itself and main (or --base). The scan also
resolves its repository from the working directory, so it runs from any
subdirectory and against any checkout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[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