Skip to content

perf: reuse nested implicit descriptor key prefixes - #1034

Merged
domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:fix/deopt-nested-key-prefix-981
Sep 10, 2026
Merged

domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:fix/deopt-nested-key-prefix-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Nested unkeyed descriptor siblings currently serialize the same wrapper path for every leaf. Reuse its encoded prefix within one multi-child scope while retaining the existing reconciliation keys and DOM identity. This is the next bounded follow-up to #981's de-opt list key finding.

Changes

  • Create the prefix lazily at the first implicit leaf; fully keyed wrappers and singleton scopes do no prefix work.
  • Keep top-level implicit indices numeric and explicit keys in their existing namespace. Object-valued paths, array toJSON, and a serializer replaced after runtime initialization use full serialization.
  • Cover escaped wrapper keys, keyed wrapper reorders, nested positional boundaries, typed input values, focus, and server hydration. Add a custom array serializer fallback regression.
  • Add an opt-in minified browser work gate with nested implicit, flat, and fully explicit lists, plus an Octane patch changeset.

Validation

  • vitest run --project octane --project octane-prod --reporter=dot: 991 files passed; 17,640 tests passed and 14 expected failures.

  • Focused key suite: 32/32 dev/prod tests. Deliberately unstable nested keys failed the four new mount/hydration cases; removing the array serializer guards failed both fallback cases. Both mutations were restored.

  • Octane and benchmark fixture tsrx-tsc --noEmit checks.

  • Scoped Prettier check, benchmark JavaScript syntax checks, git diff --check, pnpm changeset:check, and pnpm sync.

  • Baseline/candidate minified production browser work gate against d4bf228c864a33ca19ffeb0c2326e6592892ce33: identical complete HTML, row order, survivor nodes, uncontrolled input state, and focus.

  • Existing unkeyed browser work gate: reproduced the obsolete-helper lookup failure, then passed both unchanged-main and rebuilt-candidate runs with strict helper counts and all DOM/input/focus controls.

  • After merging current main (856febc73): 874 targeted key/Strong-mode tests and Octane typecheck passed. The rebuilt nested benchmark is byte-identical to the measured candidate and passes the work/semantic gate.

  • Current-head CI: 26/26 jobs passed on 94d353e9b581f2b7cc79526f3273e3bd92002bbe. The first attempt had one five-second timeout in an unchanged Vite configuration test; that file passed locally (30/30), and the failed CI jobs passed on the unchanged-head retry.

  • Cursor Bugbot passed on the current head; the unkeyed work-gate finding is fixed and its review thread is resolved.

Repository-wide pnpm test, pnpm typecheck, and pnpm format:check were not run locally; the targeted checks above cover the changed runtime and fixture.

Performance evidence

Per unrelated update in the isolated 1,000-row fixture:

Work Baseline Candidate
Nested implicit full-key JSON serializations 1,000 0
Shared path JSON serializations 0 1
Nested explicit key control 1 1
Fully explicit list key serializations 1,001 1,001
Fully explicit list prefix serializations 0 0
Flat list JSON serializations 0 0

The gate runs a transparent JSON observer separately from clean timing contexts. The normal minified fixture bundle grows from 165,458 to 165,876 bytes (+418); Node gzip grows from 53,254 to 53,418 bytes (+164). This supports a serialization-work reduction; no heap reduction is claimed. Reproduction commands are in benchmarks/js-framework/README.md under “Nested de-opt list key work gate”.

Quiet A–B–B–A confirmation (200 samples of eight updates per case, milliseconds per update):

Case A1 B1 B2 A2
Nested implicit 0.5625 0.5500 0.5625 0.5500
Flat 0.5125 0.5125 0.5125 0.5125
Fully explicit 0.5625 0.5625 0.5750 0.5625

Timing distributions overlap. The flat control also shares the changed helper; its equal median and p95 across these longer runs do not indicate a persistent common-path regression. No throughput improvement is claimed.

Risk / follow-ups

The cache is a local scalar that expires when the wrapper is flattened, with no retained state or rollback state to invalidate. Nested key strings are still created per leaf. The remaining explicit-key coercion, server nested-key work, and other #981 findings remain open.

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 child-list reconciliation key encoding; incorrect prefix reuse could cause wrong DOM adoption, though guards and extensive aliasing tests mitigate this.

Overview
Reuses a shared encoded wrapper-path prefix when deriving reconciliation keys for nested unkeyed de-opt list siblings, instead of calling JSON.stringify on the full [path, "index", index] tuple for every leaf.

The de-opt key path is refactored from scopedDeoptKey to appendScopedDeoptKey, which lazily builds a prefix at the first implicit leaf in a multi-child scope and appends the index for later siblings. Top-level implicit keys stay numeric; explicit k… keys and full JSON serialization are unchanged when paths are non-primitive, Array.prototype.toJSON is customized, or JSON.stringify was replaced after init. Single-child scopes and all-explicit lists skip prefix work via singleDeoptKey where appropriate.

Tests add nested keyed-wrapper reorders (client + hydration), escaped keys, and a custom array serializer fallback. Benchmarks add an opt-in WORK_MODE=nested Playwright gate (nested vs flat vs fully explicit 1k-row lists, JSON call counts + timing) and extend the unkeyed gate for appendScopedDeoptKey. An Octane patch changeset documents the behavior change.

Reviewed by Cursor Bugbot for commit 94d353e. 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 10, 2026 15:15
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 10, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 757053c. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
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