Skip to content

perf(octane): write unset and string native styles without a Block - #1854

Merged
trueadm merged 1 commit into
mainfrom
perf/native-style-scalar-no-block
Oct 7, 2026
Merged

trueadm merged 1 commit into
mainfrom
perf/native-style-scalar-no-block

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

In a module that imports octane/signals, every non-literal style, such as a forwarded style={props.style}, compiles to nativeStyleBinding, because the value might carry signal handles. The binding then allocated and rendered its own control-flow Block even when the value was undefined, null or a string, none of which has a native read to subscribe to. A production audit of a signed-out home page found 273 of these Blocks among roughly 1,930 hydration-time block renders, about 8 ms at 4x CPU throttling, plus the retained Blocks.

  • Client path (nativeStyleBinding). While a binding has no Block, any non-object value now takes the existing scalar writer (writeScalarNativeStyle), whatever the compiler's literal flag says. This covers undefined, null, strings, numbers, booleans, and functions, which the native read protocol never reads. It writes through setStyle exactly as the Block's body would, including hydration's keepsStyle comparison, and journals its cache for rollback.
  • Presentation hydration (presentationWrite('nativeStyleBinding')). This is the prepared-body and witness path that later swaps in the plain body, minified as jr/Mr. A scalar value now prepares the plain takeover write (setStyle(el, normalized, '')) without a Block or read witness.
  • Upgrade and reverse. The existing upgrade branch still allocates the Block, seeded with the last applied style, once a structured or handle-bearing value arrives. After that the Block stays. A later unset or string style renders through it, so its subscriptions are released by the same transactional render rather than by an untracked teardown.
  • Pre-existing hydration crash fixed. hydrateClaimedBindingCaches dereferenced binding.block! for every native style claim. Since perf: drop the signal tax from ordinary attribute, text and style bindings #1270, a scalar style literal such as style={{ opacity: props.opacity }} has no Block. In a signal-enabled 'use dom bindings' view whose early binding claimed the style, hydration threw a TypeError, surfaced as a recoverable mismatch, and rebuilt the host on the client. A Block-less binding now updates its own cache.
  • nativeProjectionBinding is unchanged. The compiler emits it only when the projection expression syntactically reads a handle (lowerNativeAttributeReads marks it reactive for x$ or x$.get()), so its Block owns real reads. Skipping that Block would mean evaluating compute() outside it, which moves read ownership and error and suspense attribution and costs a second evaluation on upgrade.

Performance

  • Deterministic counter. The signal-dom-bindings suite gains a forwarded lane: a host whose style is a forwarded string and a child whose forwarded style is unset, displaying the same CSS as the other lanes with the same host and child identity. Its observed bundle counts the native style Block allocation sites and body invocations. On main it allocates 2 style Blocks and runs 200 native style bodies per 100 updates; on this branch both are 0. Two new ratios.json guards (style_blocks and style_update_bodies, forwarded/direct, maxRatio: 0) enforce this.
  • Supplemental timing (happy-dom, paired fresh processes, median of 20 samples each). With 1,000 rows and 3,000 hosts forwarding an unset style, mount went from 11.9 to 9.9 ms and hydration from 5.3 to 4.4 ms. The branch was faster in all three pairs. This excludes browser layout and paint.
  • Bytes. No minimal or app bundle-size scenario contains these functions; I measured capture-only, hydrate-root and prop-attributes byte-identical to main, and every app's framework gzip identical (CI's bench report agrees: all app, minimal and reachability values unchanged). The signal-dom-bindings production bundle, a native-read app with style bindings, grows by 42 B raw. The full-framework ceiling bundle, which also contains the presentation-hydration and claimed-cache paths, grows by 214 B raw / 73 B gzip, within its budget. No budget changes.
  • js-framework gate. Neither fixture reaches these functions. I built the octane-tsrx and octane-jsx production bundles from both trees and they are byte-identical, so calls and DOM mutations per operation cannot change.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check on every changed file passes.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on the changed tests, runtime and bench fixture reports no new errors; the remaining errors in those files are pre-existing on main.
  • pnpm test: not run in full, to keep local load down.
  • targeted tests in the octane project, all passing: style-transaction-rollback, binding-handoff, behavior-root, signals-dom-bindings, style-object-literals, scalar-dom-bindings, binding-handoff-displaced-host, signals-rendering, strong-hook-cache, hydration/signal-instance-identity (767 tests).
  • node benchmarks/bundle-size/run-minimal.mjs --budgets and node benchmarks/bundle-size/run.mjs --budgets octane-tsrx octane-jsx hold.
  • node benchmarks/bench.mjs signal-dom-bindings --ratios --quick: all 5 applicable guards pass. That suite's separate event-owners.mjs harness fails its compile-output assertion enableSignalBindings(1, true) identically on main; that is unrelated and noted below.

New regression tests, each run native and ordinary, dev and prod:

  • Forwarded unset, null, string, false, empty and object styles match the ordinary writer, including rollback while a root render waits.
  • Unset → handle → unset: the handle updates live and is released once unset; an unmounted root ignores writes.
  • A handle upgrade rolled back while a root render waits: the abandoned attempt's read never publishes, and the retry does.
  • A handle upgrade held by a transition that suspends a visible boundary.
  • SSR output identical to the ordinary writer for unset, null, empty and string styles; hydration adopts in place with no warnings and later upgrades.
  • Presentation takeover of an early host with an unset or string forwarded style, then live updates.
  • An early binding's style publication kept through hydration for literal and forwarded styles.

Deliberate breaks, each caught:

  • Dropping the scalar cache journal fails the root-wait rollback test.
  • Taking the scalar path while a Block exists fails the release, rollback and hydration-upgrade tests.
  • Treating every non-literal value as scalar fails all of the handle tests.
  • Preparing the takeover write against undefined instead of '' fails the takeover test.
  • Reverting the hydrateClaimedBindingCaches fix makes the native-literal adoption test fail: the host is rebuilt. It fails the same way on main.

Risk / follow-ups

  • Residual risk. A binding that once received a structured value keeps its Block for its lifetime. That matches the previous behavior for those values and keeps teardown transactional.
  • Observed, not changed. In dev, the native binding reports a server style that the client leaves unset as a hydration mismatch, while the ordinary binding's unchanged-value guard skips that comparison. React would report it.
  • Observed, not changed. keepsStyle honors only per-declaration (style:<prop>) early-binding claims. An early binding's whole-string style publication is reported in dev by both writers and is not claimed, so a render that returns to the hydration-time value would not republish over it.
  • Observed, not changed. benchmarks/scoped-signals/event-owners.mjs fails its compile-output assertion on current main. It runs only in the weekly or manual bench.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


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
Touches core DOM style binding, hydration takeover, and transactional rollback paths in the runtime; behavior changes are heavily tested but affect every signal-capable forwarded or optional style prop.

Overview
Signal-enabled modules no longer allocate a native style presentation Block for style values that have nothing to subscribe to—undefined, null, strings, and plain scalar object literals. Those are written with the same scalar path as ordinary styles until a structured or handle-bearing value appears; only then is a Block created (and kept for transactional teardown on later unset/string renders).

Presentation hydration prepares scalar native style takeovers as plain setStyle writes without a Block, and claimed-binding cache adoption no longer assumes every native style binding has a Block—fixing hydration throws when an early binding claimed a scalar literal style.

Benchmarks add a forwarded style lane and ratios guards that forwarded unset/string styles allocate zero blocks and skip native style bodies; tests cover hydration handoff, rollback while renders wait, and unset → signal handle → unset upgrades.

Reviewed by Cursor Bugbot for commit 2408f1c. Bugbot is set up for automated code reviews on this repo. Configure here.

A module that imports octane/signals compiles every non-literal style, such as
a forwarded style={props.style}, to nativeStyleBinding, because the value might
carry signal handles. The binding then allocated and rendered a control-flow
Block even for undefined, null or a string, which carry no native read. A
production audit of a signed-out home page found 273 such Blocks in one
hydration (about 8 ms at 4x CPU throttling).

Any non-object value now takes the existing scalar writer while the binding has
no Block, whatever the compiler's literal flag. Presentation hydration prepares
the same plain style takeover write without a Block or read witness. The
existing upgrade still allocates the Block, seeded with the last applied style,
once a structured value arrives; the Block then stays, so a later unset style
releases its subscriptions through its own transactional render.

hydrateClaimedBindingCaches dereferenced binding.block for every native style
claim. A Block-less scalar style literal in a signal-enabled binding view made
hydration throw, so the host was rebuilt on the client; it now updates the
binding's own cache.

nativeProjectionBinding is unchanged: the compiler emits it only for
projections that syntactically read handles, so its Block owns real reads.

The signal-dom-bindings bench gains a forwarded-style lane with ratio guards:
style Blocks 2 -> 0 and native style bodies 200 -> 0 per 100 updates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 19:19
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 7, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 2408f1c Commit Preview URL

Branch Preview URL
Oct 07 2026, 07:21 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 2408f1c Commit Preview URL

Branch Preview URL
Oct 07 2026, 07:22 PM

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 6 value(s) increased within budget

Compares 7e6bda5ec, the merge commit's first parent with e391cef50 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 4.375 4.883 +7.5% −3.0% … +21.6% ⚪ within noise
octane-tsrx replace 12.342 12.333 +3.2% −13.3% … +19.0% ⚪ within noise
octane-tsrx add 4.075 4.300 −0.4% −14.6% … +17.3% ⚪ within noise
octane-tsrx update 0.198 0.205 +4.3% −2.4% … +7.4% ⚪ within noise
octane-tsrx select 0.007 0.007 +1.5% −7.0% … +6.3% ⚪ within noise
octane-tsrx swap 0.035 0.036 +3.1% −1.7% … +7.2% ⚪ within noise
octane-tsrx remove 0.019 0.019 −2.1% −7.0% … +8.8% ⚪ within noise
octane-tsrx runlots 28.700 29.758 −0.7% −4.5% … +3.6% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 ±0.0% −1.7% … +3.1% ⚪ within noise
octane-tsrx clear 51.800 51.325 +0.4% −2.3% … +2.6% ⚪ within noise
octane-jsx run 4.033 3.658 −2.6% −5.3% … ±0.0% ⚪ within noise
octane-jsx replace 7.458 7.908 +0.6% −2.1% … +3.7% ⚪ within noise
octane-jsx add 3.233 3.483 +2.9% ±0.0% … +4.1% ⚪ within noise
octane-jsx update 0.254 0.251 +0.0% −2.4% … +1.5% ⚪ within noise
octane-jsx select 0.129 0.128 −0.8% −3.5% … +0.8% ⚪ within noise
octane-jsx swap 0.242 0.227 −2.6% −4.1% … −0.6% ⚪ within noise
octane-jsx remove 0.201 0.191 −5.2% −10.1% … ±0.0% ⚪ within noise
octane-jsx runlots 30.500 31.683 +0.9% −3.1% … +3.7% ⚪ within noise
octane-jsx select_lots 1.774 1.861 +3.1% −2.0% … +6.3% ⚪ within noise
octane-jsx clear 53.333 50.300 +5.0% −1.8% … +14.1% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx full_fw_raw 564,262 564,476 +214 (+0.0%) 🔴
octane-tsrx full_fw_gzip 169,685 169,758 +73 (+0.0%) 🔴
octane-tsrx full_fw_brotli 142,780 142,889 +109 (+0.1%) 🔴
octane-jsx full_fw_raw 564,262 564,476 +214 (+0.0%) 🔴
octane-jsx full_fw_gzip 169,685 169,758 +73 (+0.0%) 🔴
octane-jsx full_fw_brotli 142,780 142,889 +109 (+0.1%) 🔴

54 other measured values are unchanged.

Public-import reachability bundles (bytes)

No changes across 108 measured values.

@trueadm
trueadm merged commit 0d95b26 into main Oct 7, 2026
51 of 54 checks passed
@trueadm
trueadm deleted the perf/native-style-scalar-no-block branch October 7, 2026 19:58
trueadm added a commit that referenced this pull request Oct 7, 2026
Conflicts: app-budgets.json and minimal-budgets.json, where #1854 and
#1855 lowered the rows this branch had tightened. Take main's values,
then write this branch's measurements (`--write-budgets`) on the merged
tree, which only lowers: bindings app gzip and total raw, one app
brotli, and three minimal gzip rows. hydrate-frame stays at main's
364,882 raw. It measures 364,886 here and on main alike, and main's own
CI fails the same check, so the raise belongs in a budget-only change on
main, not in this PR.

#1852 stops the Vite plugin parsing modules it only passes through, such
as the SSR chunks Nitro re-bundles. The @tsrx/core patch still bounds
every module the plugin does compile, so its guard now transforms a
540 kB project module that uses a hook instead of a Nitro chunk: about
2 s patched, 20 s unpatched, against a 6 s bound. The patch note says
so.

Reformat main's new hydrate-frame fixture; its output is unchanged once
position-derived ids are masked. main's changed test files pass on this
branch (bundler-compiler, compiler-vite-options, behavior-root,
binding-handoff, style-transaction-rollback).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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