Skip to content

perf: specialize compiler-proven keyed selection updates - #613

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/keyed-selection-compiler-invalidation
Aug 7, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/keyed-selection-compiler-invalidation

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Automatically recognize production @for rows whose class depends only on a strict comparison between the selected value and the row's authored key. Emit a tree-shakable compiler-only capability that updates only the previously selected and newly selected keyed rows while preserving component rerenders and existing public APIs.
  • Fall back to ordinary reconciliation for immutable row replacements, changed parent dependencies, mismatched keys, additional selection captures, hydration, and suspended transitions. Add behavioral coverage for each case, including transition rollback followed by an urgent update.
  • Repair the framework benchmark's repeated-selection no-op, validate the selected DOM outside the timed window, and add a 10,000-row same-run TSRX/JSX regression guard.
  • Part of Performance roadmap: targeted updates, JSX lowering, DOM mounting, SSR, reconciliation, and bundle budgets #611.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — 1,555 test files / 16,519 tests passed (NODE_OPTIONS=--no-experimental-webstorage restores jsdom storage under local Node 26; CI uses Node 22/24).
  • targeted tests: pnpm exec vitest run --project octane --project octane-prod packages/octane/tests/for.test.ts packages/octane/tests/transitions.test.ts packages/octane/tests/hydration/for-hydrate.test.ts packages/octane/tests/auto-memo.test.ts — 236 passing tests; compiler suite: 852 passing tests.
  • node benchmarks/bench.mjs --quick --ratios js-framework — all eight framework targets and all nine applicable ratio guards pass; 10,000-row selection: 0.10 ms TSRX vs. 1.10 ms JSX.
  • Browser precise coverage: 1,000 → 2 row-body executions, 1,000 → 0 survivor visits, and 5,052 → 57 observed production calls. Order-balanced baseline/candidate timing at 10,000 rows: 0.225 ms → 0.0125 ms (18× faster).
  • node benchmarks/bench.mjs --quick codegen-size bundle-size — eligible corpus adds 4 gzip bytes; a noneligible TodoMVC app and framework chunks are byte-for-byte identical to upstream HEAD.

Risk / follow-ups

  • Specialization is intentionally restricted to production-only, host-only, explicitly keyed @for rows with one static-arm class comparison. JSX .map() and more general selection expressions remain future work.
  • Existing global codegen/bundle ratio ceilings are stale on upstream HEAD itself: the untouched HEAD compiler already measures 26,530 / 24,722 = 1.073× against the historical 1.04× ceiling. The new same-run selection guard passes, and nonparticipating applications pay zero shipped bytes.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Changes compiler emission and @for runtime reconciliation for a narrow, proof-gated pattern; fallbacks and broad tests limit blast radius, but incorrect proofs could cause stale row UI.

Overview
Adds a compiler-proven keyed selection fast path for production @for rows where the host root’s sole class/className is a static ternary comparing a captured parent value to the row’s authored key (selected === item.id or the reverse). Eligible lists emit tree-shakable keyedForBlock (not forBlock) and encode the selection dependency in forBlock flags; everything else keeps ordinary keyed reconciliation.

Runtime: When the items snapshot and non-selection deps are unchanged, tryUpdateKeyedSelection re-invokes only the blocks for the old and new selected keys instead of walking the full list. Transitions, hydration, iterable identity changes, extra captures of selected, shared bindings, and mismatched key vs selection property fail closed to full forBlock behavior.

Benchmarks: select alternates rows so timing isn’t a no-op; new select_lots on 10k rows plus an untimed DOM selection gate; ratios.json adds a same-run TSRX vs JSX ceiling for select_lots.

Tests: New fixtures and cases cover DOM identity, custom keys, hydration, reorder/remove, immutable item updates, and selection during suspended transitions.

Reviewed by Cursor Bugbot for commit faaea44. 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 August 7, 2026 15:35
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 7, 2026
@trueadm
trueadm merged commit 1a27e19 into octanejs:main Aug 7, 2026
50 of 52 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.

2 participants