Skip to content

perf: avoid per-list key callback wrappers - #1057

Merged
domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:fix/deopt-list-key-callback-981
Sep 11, 2026
Merged

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

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Remove the per-list key callback selected by renderPreparedChildList: reconciliation now reads the prepared key array directly or calls the existing compiled-map key function with normalization at the original read site.

Partial follow-up to #981. Explicit/nested key encoding and keyed component-slot coercion remain open.

Changes

  • Keep each key source local to its reconciliation call, preserving nested/reentrant rendering without retained caches.
  • Preserve raw @for key identity, the public callback's two arguments and receiver, key/coercion evaluation order, development duplicate-key diagnostics, and empty-fill/error cleanup.
  • Add behavioral coverage for nested descriptor reorders, mapped hydration and map-mode transitions, object keys, callback arguments, and failed-list retry.
  • Correct a pre-existing compiler mismatch exposed by that regression: guarded-map component roots now retain full component-slot ownership across native/custom dispatch, including compatible single-root boundaries. Ordinary @for output remains unchanged.
  • Add an opt-in production browser work gate with descriptor, native mapped, and compiled @for controls, plus a patch changeset.

Performance evidence

  • 512 small descriptor lists: selected callback construction executions 512 → 0 per mount/update/reorder/restore.
  • 512 native mapped lists: selected normalizing callback construction executions 512 → 0 per phase.
  • Compiled 2,048-row @for control: 0 → 0. All cases preserve full markup, survivor nodes, typed input values, and focus.
  • Final minified fixture bundle: 176,950 → 177,057 bytes; gzip 56,488 → 56,526 bytes (+107/+38).
  • Paired warm timing distributions overlap; no throughput or V8 heap-allocation improvement is claimed. Short, coarsely timed compiled-update runs showed a warmup-sensitive difference; higher-batch measurements did not establish a steady-state regression. An inline-dispatch alternative added another 226 raw/78 gzip bytes without a reliable timing benefit and was discarded.
  • Reproduction commands, all timing ranges, artifact checksums, and limitations are recorded in the benchmark README.

Validation

  • Production browser work and semantic gates, paired timing controls, and minified bundle comparison.
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/typetests/tsconfig.json
  • Scoped formatting for all changed files; git diff --check; test-marker check.
  • pnpm sync
  • Related dev/prod, hydration, list, root-error, and compiler suites: 49 files / 856 tests passed (includes the 216 tests in the two directly affected files). Three deliberate key-handling mutations each made the corresponding regression fail in both dev and prod; the runtime was restored exactly.
  • Full pnpm test, pnpm typecheck, and repository-wide formatting were not run.
  • Current-head CI: 26/26 jobs passed on signed head bf66a67a4. The merge incorporates main fix: stabilize main CI failures #1056, fixing the prior Three camera type failure and Solana module-reload timeout. Cursor Bugbot passed, all review threads are resolved, and the worktree is clean. GitHub still requires reviewer approval before merge.

Local tests used a temporary selection of the repository's existing octane/octane-prod projects, retaining their compiler plugins, exclusions, environments, and per-test setup. The unrelated React differential-fixture precompile was omitted because the selected suites do not use it. No additional dependency download was needed. Commands: vitest run --config /private/tmp/1057-vitest.config.mjs (216 tests), then vitest run --config /private/tmp/1057-related-vitest.config.mjs --maxWorkers=4 (856 tests).

The rebuilt production work fixture matches the measured candidate byte-for-byte (6b19ce09eb24956a00c0da2bdb26557b3bba227ed65aa1b4c2e3492e549522a8). Standard production/server mapped fixtures and ordinary @for output are unchanged. Dev and autoMemo:false guarded component maps now pay for a full component slot to preserve transitions; measured emitted-code deltas were +5/+17 bytes, not a heap-cost measurement.

CI attempt 1 hit a Vitest browser-orchestration error while starting the adapted Base UI MeterTrack.test.tsx, with no assertion failure reported. That exact Chromium fixture passed 15/15 tests locally. The targeted shard retry and its dependent checks passed without further code changes; the underlying browser error cause was not available in the CI log.

Risk / follow-ups

This touches key reads in the shared client reconciler and component-slot selection for guarded map item roots. The original failing hydration scenario is preserved. No server implementation or public/compiler ABI changes. Current-head CI is green; the full local differential suite was not run.

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

High Risk
Changes keyed reconciliation in the shared client runtime and compiler component-slot selection for map item roots—areas that affect hydration, list identity, and reorder correctness.

Overview
Removes per-list key callback wrappers in the de-opt child-list path: reconciliation now reads prepared key arrays directly or invokes compiled map key functions at each read site via readListKey, eliminating 512 executed callback constructions per phase in the new work gate while keeping @for callback semantics, duplicate-key diagnostics, and hydration behavior.

Fixes guarded .map item roots in the compiler by passing mappedItem into planJsx so component map roots always use a full component slot (not a lite scope), preserving DOM/input identity when switching between native Array.prototype.map and a custom map implementation.

Adds an opt-in WORK_MODE=key-callback browser benchmark (descriptor lists, native mapped lists, compiled @for control), README evidence, a patch changeset, and expanded tests for nested descriptor reorders, mapped hydration, object keys, and manual forBlock key errors.

Reviewed by Cursor Bugbot for commit bf66a67. 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 Sep 11, 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 7e3a8e7. Configure here.

Comment thread packages/octane/tests/for.test.ts Resolved
@domgan-oai
domgan-oai marked this pull request as ready for review September 11, 2026 22:04
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