Skip to content

perf: drop the signal tax from ordinary attribute, text and style bindings - #1270

Merged
trueadm merged 2 commits into
mainfrom
perf/signal-free-binding-tax
Sep 23, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/signal-free-binding-tax

Conversation

@trueadm

@trueadm trueadm commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This fixes items C1–C3 from the 2026-09-22 review sweep (the "signal tax" first reported in #1130). Ordinary code with no signals import was paying for the signal binding path in bundle size, and modules that import octane/signals were paying for it in per-row style Blocks.

C1: prop-driven attributes (size). In a module with no signals import, an opaque value such as title={props.label} still compiles to bindSignalAttribute. The runtime then sent the plain attribute case to the generic setAttribute. That pulled setValue/setChecked/setSelectValue, armControlled, the restore helpers, dom-tables.js and sanitize-url.js into every such bundle: +7.0 KB gzip (+25%) for a one-component counter. #1141 split the value and checked policies, but the attribute policy still reached every control writer through that fallback.

  • The compiler now passes the writer it already selects for the ordinary binding (setPlainAttribute, setURLAttribute, setStringData, setAriaAttribute, setBooleanAttribute) as the writer argument. writeDirectSignalAttribute has no generic fallback anymore. class stays a string tag because its writer depends on the namespace. Development builds still pass the generic setAttribute, as before.

C2 (size). createDirectSignalBinding called isRestoredHydrationTextarea directly, which put hydration/control-capture.ts into every text and attribute binding. It is now reached through DIRECT_SIGNAL_CONTROL_POLICY.restored. Only control policies take a snapshot, so the behaviour is unchanged.

C3: styles in native-read modules (perf). In a module importing octane/signals, style={{ color: props.color }} created a per-element control-flow Block and rendered it on every update.

  • The compiler now marks a style that is an object literal of plain data properties. When every value is a scalar, nativeStyleBinding writes it directly, with transition journaling of its style cache. It creates the Block only when a structured value first appears, starting from the style already applied. After a Block exists, that element keeps using it.
  • Components whose body is only lowercase host elements with literal values skip the beginNativeReadScope/endNativeReadScope try/finally. The check allows only listed node types and applies on the client only.

Budget gap. None of the existing minimal fixtures exercised a prop-driven attribute, which is why the budgets missed C1. This adds fixtures/minimal/prop-attributes.tsrx. It checks behaviour in the production runtime, including that a javascript: href is sanitized, and asserts that dom-tables.js and control-capture.ts are absent from the bundle. It gets a budget (about 3% headroom), three maxRatio: 1 guards, and a place in the per-PR CI budget step.

Measurements (production Vite, measured locally on Node 24.18)

Before and after on the same base (c25a185):

gzip bytes before after
prop-attributes fixture 36,686 31,574 (−5,112)
title={props.label} counter 35,231 29,793 (−5,438)
cli-spa-starter 43,494 38,061 (−5,433)
context / hydrate-root / deferred-hydration / suspense-transition / mantine-hooks / usehooks-ts −58 to −92 each

No other bundle-reachability scenario grew; one esbuild bundle differs by 1 byte. On the rebased head (2554d85, where main itself grew about 250 B), prop-attributes measures 31,830 against its 32,528 budget.

Style, 2,000 rows × (mount + 10 updates) in jsdom, in a module that imports octane/signals:

  • Operation counts: createBlock 4,001 → 2,001 and renderBlock 44,011 → 22,011. The per-row style Blocks are gone.
  • Timing: the fastest of 12 interleaved runs went from 238 ms to 141 ms for updates, level with the equivalent plain module (146–178 ms). The machine's load average was about 50 during this run, so treat the timing as indicative only.

Validation

  • pnpm format:files:check on the changed files
  • pnpm format:check: not run repo-wide
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files reports one error, in tests/compiler/signal-bindings.test.ts:2 (@tsrx/core has no declaration file). That import line is unchanged from main.
  • pnpm test: the full run crashed with an out-of-memory error in the vitest main process after about 3.2 h, while the machine's load average was around 50. Before the crash, failures were timeouts across unrelated packages, plus a few hydration files that passed 452/452 on two reruns at lower load.
  • targeted tests:
    • The octane, octane-prod and all octane-signals* projects on c25a185 plus this change: 1,223 files, 23,514 tests passed.
    • On the rebased head: the signal, style and compiler suites below, 366 tests passed.
    • node --test scripts/ci-workflow.test.mjs and node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local hooks-state prop-attributes context both pass.

New regression tests. Each was seen to fail with the implementation deliberately broken.

  • Attribute writers: compiler/signal-bindings.test.ts checks the writer each attribute gets, including that production never uses the generic setAttribute. signals-dom-bindings.test.ts covers handles and scalars for every writer kind with dev and prod compiles. The prod case stubs NODE_ENV=production, because otherwise the narrow writers delegate to setAttribute in tests.
  • Style: signals-dom-bindings.test.ts moves an object-literal style between scalars and signal handles for both fresh render and hydration, in dev, prod and strong compiles.
  • Style rollback: style-transaction-rollback.test.ts now also runs with import 'octane/signals'. Removing the scalar-path journal entry makes 6 of its cases fail.
  • Native-read wrapper: compiler/native-reads.test.ts checks that the wrapper is kept for component tags, destructured parameters, setup statements and dynamic values.

Risk / follow-ups

  • Internal ABI change: the last argument of bindSignalAttribute changed from a kind string to a writer function (or 'class'). It is a private octane/internal/client helper, and the compiler and runtime ship together.
  • Not removed: _$enableSignalBindings(1, true) is still emitted for signal-free modules and accounts for the remaining ~1.6 KB. The runtime comments say it keeps component identities so that a signals module loaded later still works, so removing it is a design decision rather than a size fix.
  • Possible follow-up: the compiled per-component native-read wrapper looks redundant with the scope the runtime already opens for each component. I didn't prove that, so I didn't change it.
  • Unchanged: the SSR native-read wrapper.
  • Pre-existing failure: binding-aria-esbuild in the full reachability suite fails to build on main as well (Unexpected "enum" in TokenFieldValue.tsx).

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 compiler emission and private bindSignalAttribute / direct-signal binding ABI plus native style and hydration paths; mitigated by new fixture gates and broad regression tests.

Overview
Reduces bundle size and runtime work when code uses prop-driven DOM bindings or plain style objects without actually importing signals.

Prop-driven attributes and text now pass the compiler’s statically chosen scalar writer (e.g. setPlainAttribute, setURLAttribute) into bindSignalAttribute instead of routing through generic setAttribute and form-control DOM tables. Text/attribute direct bindings only pull restored-textarea hydration through control policies, not every binding.

Native style bindings in signal modules can write plain object-literal styles directly and defer allocating an owning Block until a non-scalar or handle-backed value appears; scalar caches journal for transitions and rollback.

Pure static host components (literal markup only, no setup/destructuring/component tags) skip the native-read scope wrapper around render.

Benchmarks/CI add the prop-attributes minimal fixture with byte budgets and reachability checks that dom-tables.js and control-capture.ts stay out of signal-free prop-attribute bundles.

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

…dings

Opaque props in a signal-free module lower to potential signal bindings.
bindSignalAttribute routed statically named attributes through the generic
setAttribute, retaining every form-control writer, dom-tables.js and
sanitize-url.js (+7 KB gzip for one `title={props.label}`). The compiler now
passes the writer it already selects (setPlainAttribute, setURLAttribute,
setStringData, setAriaAttribute, setBooleanAttribute), so the runtime has no
generic fallback. The restored-textarea check moves behind the control policy.

In native-read modules, a style object literal whose values are all scalars is
written directly and allocates its owning Block only when a handle appears.
Components that evaluate no authored code skip the native-read bracket.

Adds a prop-attributes minimal bundle fixture with a budget, ratio guards and
a per-PR CI gate, since the existing fixtures never exercised this path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 23, 2026
@github-actions
github-actions Bot marked this pull request as draft September 23, 2026 08:22

@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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Style block upgrade skips rollback
    • Added journalRootProperty(binding, 'block', binding.block) before the assignment in the scalar-to-block upgrade branch so rollback restores binding.block to null, preventing dangling references to disposed blocks.

Create PR

Or push these changes by commenting:

@cursor push 2e2920de31
Preview (2e2920de31)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -1278,6 +1278,7 @@
 		const block = createBlock('control-flow', owner.block, el, null, null, body, props);
 		block.parent = owner;
 		if (binding.el === el) block.slots[0] = binding.style;
+		journalRootProperty(binding, 'block', binding.block);
 		binding.block = block;
 	} else {
 		const block = binding.block!;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 699ab35. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@domgan-oai

Copy link
Copy Markdown
Contributor

@cursor push 2e2920d

@domgan-oai
domgan-oai marked this pull request as ready for review September 23, 2026 09:43
The scalar-to-block upgrade path in nativePresentationBinding assigned
binding.block without journaling it. On transition rollback, the
JOURNAL_CREATED entry would unmount and dispose the block, but
binding.block still pointed at the disposed block, leaving a dangling
reference that could cause later renderBlock calls to operate on a
disposed block or let the block keep writing styles after rollback.

Add journalRootProperty(binding, 'block', binding.block) before the
assignment so rollback restores the binding to the scalar path.

Applied via @cursor push command
@trueadm
trueadm merged commit 3249c9a into main Sep 23, 2026
29 checks passed
@trueadm
trueadm deleted the perf/signal-free-binding-tax branch September 23, 2026 11:52
trueadm added a commit that referenced this pull request Sep 23, 2026
… fast path

#1282 removed `hydrateAttributeProbe` along with the side-render capture it
served, deleting this exact guard from `nativePresentationBinding`. #1270,
branched earlier, copied that guard into its new scalar-literal fast path in
`nativeStyleBinding`. Both merged, leaving main referencing an undefined
name: `tsc` fails (TS2304), the octane build and every package pack fail,
and in dev the fast path throws `ReferenceError: hydrateAttributeProbe is not
defined` (#1270's own style-transaction and signal-binding tests fail).

Drop the guard to match #1282's removal in the general path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Sep 23, 2026
… fast path (#1283)

#1282 removed `hydrateAttributeProbe` along with the side-render capture it
served, deleting this exact guard from `nativePresentationBinding`. #1270,
branched earlier, copied that guard into its new scalar-literal fast path in
`nativeStyleBinding`. Both merged, leaving main referencing an undefined
name: `tsc` fails (TS2304), the octane build and every package pack fail,
and in dev the fast path throws `ReferenceError: hydrateAttributeProbe is not
defined` (#1270's own style-transaction and signal-binding tests fail).

Drop the guard to match #1282's removal in the general path.

Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 3, 2026
The compiled/source gzip guard (maxRatio 1.06) records 26132 / 24713 from
136b0e3 (#638). The suite wrote no numbers from 2026-09-16 until its Rspack
chunk assertion was fixed, so nothing checked it. Main now measures
35039 / 27077 = 1.294x.

Splitting the growth:
- Compiler: the 136b0e3 corpus files the current compiler still accepts
  (14 of 16) compile to 22338 -> 25107 gzip. A sampled timeline plus git
  bisect over that fixed set names 5ead1ff (#1069): +2065 B in one step,
  because every opaque text and attribute binding became signal-capable.
  #1270 kept that design while removing its runtime tax. The rest is gradual.
- Corpus: tests extended the context, boundary, control,
  controlled-forms-diff and components fixtures. Source gzip rose
  24713 -> 27077 and those fixtures add the remaining +6138 compiled bytes.

Both are intended, so the ceiling moves to 1.30, leaving 161 B.

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.

3 participants