Skip to content

perf: skip unchanged composed class writes - #996

Merged
domgan-oai merged 4 commits into
octanejs:mainfrom
openai-oss-forks:codex/guard-composed-class-981
Sep 8, 2026
Merged

domgan-oai merged 4 commits into
octanejs:mainfrom
openai-oss-forks:codex/guard-composed-class-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Why

Fresh object and array literals have a new identity on every render, even when normalizeClass returns the same string. The compiler currently omits the previous-value binding field and calls the DOM class setter unconditionally. In a repeated row this invokes browser class invalidation for unchanged values.

Changes

  • Normalize fresh class literals once per render, save the string in the existing binding bag, and use the ordinary changed-value guard.
  • Keep nullish/false removal semantics on the nonfresh path; a fresh literal is always truthy, including when it composes to an empty string.
  • Add a patch changeset and public DOM mutation and suspended-root regression coverage.
  • Expose the two private compiler helpers through the evaluator’s bounded runtime bridge so generated user-app fixtures execute against the same runtime.

Validation

  • node --check packages/octane/src/compiler/compile.js
  • git diff --check and scoped cached Prettier check for changed JS/TS/Markdown
  • node scripts/workspace-packages.mjs --check
  • pnpm sync, local Vitest and typecheck: the configured dependency registry is currently preventing the pinned TSRX package from installing in a fresh worktree; generate-version.mjs ran without changing tracked files.
  • Pinned baseline and candidate used identical workflow/lockfile blobs. Weather raw: 22,595 → 22,619 bytes (22,624 budget); no new ratio breaches (57/95 on both). Compiled corpus raw/min/gzip: 159,633/78,003/27,898 → 159,919/78,133/27,927 bytes. The identical scratch workflows supply TodoMVC’s missing window.__benchFlush = () => flushSync(() => {}) adapter so each dispatched event commits before verification; both sides pass all eight correctness targets, with exact changed-row class writes of 25 and identical DOM census. Timings on separate hosted runners are inconclusive.
  • Pinned pre-fix RED: the new unchanged-class DOM mutation assertions failed in both dev and prod on merged main (four intended failures, 72 other tests passed).
  • Current-head CI attempt 2 on 3d18ef459: 26/26 jobs successful. An unrelated pristine Input OTP browser selection test failed on attempt 1 and passed on the identical-head retry.

Risk / follow-ups

  • The optimization changes the prior fresh-literal behavior of reasserting an externally edited class on an unrelated render. It matches the existing value guard for scalar class bindings.
  • A fresh class literal retains one additional previous-value field in its binding bag; benchmark results will quantify output and runtime tradeoffs.

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
Changes reactive class DOM write timing for fresh literals (aligned with scalar *IfChanged guards), so externally mutated classes may not be reasserted on unrelated re-renders; core binding and SVG routing paths are touched.

Overview
Fresh object/array/function class bindings no longer hit the DOM on every render when normalizeClass produces the same string. The compiler now routes those updates through updateFreshClassName / updateFreshClassAttr, caches the composed string in the binding bag’s _prev field (including deferred mounts), and normalizes fresh literals on mount/update so empty compositions still emit class="" instead of removing the attribute.

The eval client runtime re-exports the new helpers. Tests use MutationObserver to assert skipped class mutations on no-op re-renders (HTML objects and SVG arrays), and the suspended-root fixture now covers object class during scope hold/rollback.

Reviewed by Cursor Bugbot for commit 3d18ef4. 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 8, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 8, 2026 15:43
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