Skip to content

perf: add conservative binding dirty masks and immutable provenance - #695

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-binding-dirty-masks-immutable-provenance
Aug 10, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-binding-dirty-masks-immutable-provenance

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Cache compiler-proven, pure native filter projections over private immutable useState([]) snapshots in production .tsrx components.
  • Reuse existing binding cells to skip unchanged single-token class updates without weakening controlled value/checked restoration.
  • Add an exact Chromium production-work gate for the existing TodoMVC application, with no fixture or application-source changes.
  • Document the narrow provenance contract and add the required octane patch changeset.

Refs #673.

Correctness and scope

The compiler requires a genuine empty-array state initializer, a closed nonescaping setter, proven fresh array updates, pure own-data-property predicates, and nonescaping derived collections. The runtime guard runs only after existing memo dependencies already match and rejects non-native methods, overridden constructors/species, sparse arrays, indexed or item getters, and unproven snapshots.

Unsafe aliases, impure predicates, loose coercive conditions, side-effecting conditions, escaped derived arrays, arbitrary live receivers, development compilation, server rendering, and returned JSX retain their original behavior. Controlled fields continue to reassert their values on every commit.

Four independent public regressions were reproduced before fixing the proof: loose Symbol.toPrimitive coercion, earlier mutating predicates, side-effecting update expressions, and derived arrays escaping to unknown callbacks.

Production work

Existing 100-todo interaction Filter predicate calls before → after Filter-tab class writes before → after Controlled checkbox writes after
Start editing 200 → 0 3 → 0 76
Cancel editing 200 → 0 3 → 0 76
Change active filter 200 → 100 3 → 2 26
Toggle a todo 200 → 200 3 → 0 1

The gate also checks all visible rows, keyed survivor identity, selection, editor state, footer totals, controlled-checkbox restoration, and necessary text updates. Generic root, Suspense, and hydration production bundles remain byte-identical; all 15 unrelated compiler-corpus entries and TodoMVC server output are unchanged. The optimized TodoMVC application grows by 355 gzip bytes, and its compiler-corpus entry grows by 145 gzip bytes. Session-to-session browser timings were too noisy to support a reliable duration claim; the deterministic work counters are the acceptance signal.

Validation

  • ./node_modules/.bin/vitest run --project octane --project octane-prod --silent=passed-only — 804 files, 11,851 tests passed.
  • pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run typecheck — complete workspace passed on the latest upstream base.
  • Expanded compiler, hydration, provenance, universal-renderer, Suspense, transition, and conformance suites — 174 files, 3,209 tests passed.
  • Newly merged Lynx renderer project — 24 files, 320 tests passed.
  • Focused public provenance, controlled-input, getter/proxy/species, hydration, and four RED→GREEN regressions — 34 cases passed.
  • Final production Chromium TodoMVC work gate, unchanged generic production bundles, fixed compiler-output corpus, server-output parity, and compiler-throughput comparison.
  • Frozen parsed AST and exact source-location assertions across client/server and development/production compile modes.
  • Scoped Prettier checks, git diff --check, and pnpm --config.verify-deps-before-run=false sync.

Risk / follow-ups

  • The specialization intentionally supports only closed, compiler-proven immutable state snapshots and a single safe class token. Arbitrary member calls, unsupported aliases, impure predicates, controlled bindings, and more general class-object ordering remain on their established paths.
  • The optimized TodoMVC bundle adds 355 gzip bytes; unrelated production bundles remain unchanged.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches production compiler memoization and DOM class binding lowering with a runtime snapshot guard; scope is intentionally narrow and heavily tested, but incorrect provenance could still cause stale UI if guards fail.

Overview
Adds compiler provenance so production .tsrx can wrap eligible todos.filter((todo) => !todo.completed)-style projections in memoization when the array comes from a closed useState([]) with only proven-immutable setter updates and a simple own-property predicate. Generated memo paths call new runtime compilerCacheImmutableArrayFilter only on would-be cache hits to confirm dense plain snapshots (native filter/map, no getters/proxies/overrides) before reusing the filtered array identity.

Class bindings from a single-key object like class={{ selected: filter === 'active' }} can lower to a conditional string when filter is proven primitive state in the same component, reusing the existing binding dirty mask so unchanged filter tabs skip redundant class DOM writes; controlled value / checked still reassert every commit.

Docs describe the narrow contract; benchmarks/todomvc/work.mjs (bench:work) is an untimed Chromium gate on the existing Octane TodoMVC build that asserts filter-predicate call counts, filter-tab class mutations, keyed rows, and controlled-field restoration. Extensive auto-memo tests cover hydration, getters, species overrides, escaped aliases, and impure predicates.

Reviewed by Cursor Bugbot for commit d37c166. 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 20:10
@trueadm
trueadm merged commit 50b7988 into octanejs:main Aug 10, 2026
53 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