Skip to content

perf: specialize mixed static and dynamic style objects - #692

Merged
trueadm merged 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/673-specialize-mixed-style-objects
Aug 10, 2026
Merged

trueadm merged 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/673-specialize-mixed-style-objects

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Specialize compiler-proven inline style objects containing a nonempty static prefix and exactly one dynamic property.
  • Bake the static declarations into template HTML, retain the existing deferred evaluation order, and update only the changed dynamic CSS property without allocating a complete style object.
  • Preserve exact development hydration behavior with narrowly scoped template-host metadata, including nested hosts, fragments, SVG, and genuinely static structural mismatches.
  • Add a deterministic production Chromium style-work gate to the existing 1,000-row benchmark while keeping its returned-JSX fixture as an unchanged control.

Refs #673.

Correctness and scope

The optimization fails closed for spreads, computed or duplicate CSS keys, accessors, reordered declarations, direct hydration suppression, and unsupported renderer paths. Existing behavior remains covered for shorthand/longhand ordering, initially absent longhands, CSS custom properties, numeric units, !important, null/boolean removal, SVG, source evaluation order, server rendering, hydration mismatch recovery, DOM adoption, and suspended-transition rollback.

Server output is unchanged. The returned-JSX benchmark source and production artifact remain byte-identical.

Production benchmark

Existing 1,000-row operation Whole-style reconciliations before Whole-style reconciliations after Dynamic property writes after
Mount 1,000 0 1,000
Select one row 1,000 0 1
Select another row 1,000 0 2
Unrelated update 1,000 0 0

The static property is never rewritten. Same-source, production-minified Chromium measurements improved selection from 2.0 ms to 0.7 ms and kept mount time at 2.8 ms. The representative application grew 77 gzip bytes; all 15 unrelated compiler-corpus entries and the returned-JSX control remained byte-identical.

Validation

  • ./node_modules/.bin/vitest run --project octane --project octane-prod --silent=passed-only — 804 files, 11,779 tests passed.
  • pnpm --config.verify-deps-before-run=false --config.enable-pre-post-scripts=false run typecheck — full workspace passed.
  • Broad affected compiler, style, hydration, transitions, and conformance suites — 148 files, 2,693 tests passed.
  • Focused public CSS/hydration/transition regressions — 50 cases passed across development and production.
  • Existing real-Chromium style hydration suite — 2 tests passed.
  • Production Chromium style-work gates for both the optimized TSRX fixture and unchanged returned-JSX control.
  • Frozen parsed AST, source-location assertions, server-output parity, codegen corpus, generic bundle reachability, formatting, and pnpm --config.verify-deps-before-run=false sync.

Risk / follow-ups

The specialization deliberately covers a single dynamic property following safe static declarations. More complex object ordering and returned-JSX descriptor extraction continue through their existing paths.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches compiler lowering, runtime style updates, and dev hydration matching—areas where subtle CSS-order or SSR/client divergence bugs are possible, though the change fails closed and adds broad tests plus a production style-work gate.

Overview
Specializes inline style={{ …static literals…, dynamicProp }} when the compiler can prove a nonempty static prefix and exactly one dynamic property: static CSS is baked into the template, and updates go through setStyleProperty instead of whole-object setStyle.

Unsafe shapes (spreads, computed keys, multiple dynamic props, etc.) still use the existing style diff path.

Runtime and hydration gain partial-style metadata on clone() so dev hydration compares the full computed style while tolerating template style attributes that only carry the static prefix; applyStyle / setStyleProperty merge the baked prefix with the dynamic value.

Benchmarks: the naive TSRX row fixture uses a mixed style (static fontStyle + dynamic fontWeight); bench:style-work is a Chromium gate that asserts per-property writes and zero whole-style reconciliations on the optimized path, with JSX as control.

Reviewed by Cursor Bugbot for commit 8bdc9c6. 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

@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 c7c74b5. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@trueadm
trueadm marked this pull request as ready for review August 10, 2026 19:04
@trueadm
trueadm merged commit 910c240 into octanejs:main Aug 10, 2026
50 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