Skip to content

perf(signals): skip re-rendering adopted readers whose live values are unchanged - #1862

Merged
trueadm merged 3 commits into
mainfrom
perf/adoption-release-unchanged-reads
Oct 7, 2026
Merged

trueadm merged 3 commits into
mainfrom
perf/adoption-release-unchanged-reads

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

After a hydration commit, releaseNativeAdoptions releases each adoption frame. Releasing a frame (AdoptionFrameImpl.release → untrack(notify) → scheduleNativeRead) notified every Block that read a signal while hydrating, so each one rendered again in the same task. That happened even when the live value still equalled the server value. Parents render their children, so a section-level read rendered the whole section twice.

Release now renders a reader again only when something it read changed.

  • Unchanged reads move live. Before notifying, release offers each historical read to its subscribers. A renderer consumer whose committed render alone holds that read asks for its live successor. If a live read would present the same value, the consumer moves its committed read and subscription to the live node and is not notified. A snapshot read must also match the server's status and activity metadata.
  • Changed reads still re-render. Every other read re-renders as before: an early edit, a newer query result, a changed or pending selection, a later stream value, or a stream that completed under a snapshot read. Decoded objects are fresh copies, so object reads re-render too.
  • Targeted bindings get their own channel. A binding such as {value$} reads through a separate historical channel. On an unchanged release that read is dropped rather than moved, because the binding already holds its own live subscription. The component therefore never starts depending on the signal.
  • Only hydrating bundles pay for the rebase. The consumer-side move is a standalone rebaseNativeRead, which ownNativeAdoption registers.

Performance

benchmarks/app-frame-hydration (from #1857, run from a local copy and not part of this diff), measured with node benchmarks/app-frame-hydration/run.mjs 20 --base=<origin/main 188d60b38d>. Head/base ratios are over 20 interleaved pairs, with bootstrap 95% CIs, at 4× CPU throttle:

scenario renders (blocks) cold warm heap
frame-live-sections 3,078 → 1,653 (1,653) 0.886 [0.872–0.913] (98.2 → 87.4 ms) 0.873 [0.854–0.884] (47.3 → 41.2 ms) 4.83 → 4.15 MB
frame 1,703 → 1,653 (1,653) 0.972 [0.943–0.995] 0.957 [0.940–1.012] 4.18 → 4.15 MB

Renders now equal Blocks in both scenarios. Every sample still verifies that every server element is adopted, that no recoverable error is raised, and that a delegated click re-renders a native-read arm. That click is the semantic control: it only works if the moved reads are subscribed live.

Size. Only hydrate-frame in the minimal suite grows: +1,146 raw, +488 gzip, +249 brotli. Every app and JSX budget is byte-identical. That is over the +32 headroom, so the raise is in budget-only #1863, which must merge first.

Validation

  • pnpm format:check (scoped pnpm format:files:check on every changed file passes)
  • pnpm typecheck (scoped pnpm typecheck:files on the changed sources, tests and .tsrx fixtures passes)
  • pnpm test (left to CI)
  • targeted tests:
    • signals-hydration.test.ts in octane-signals, octane-signals-prod and octane-signals-strong.
    • hydration/streamed-query-hydrate.test.ts and hydration/direct-signal-bindings.test.ts in octane and octane-prod.
    • hydration/initial-document-signals.test.ts.
    • signals-native-seeds, signals-serialization and signals-inspection in octane-signals-node.
    • Before the merge with main, the full packages/octane/tests/signals* set and the hydration signal files also passed across the five signals and octane projects.

New regression tests assert render-time side effects and DOM, not internals:

  • A section reader renders once when the live value equals the server value, and a later write still renders it.
  • The reader renders again when the live value differs.
  • A binding-only component renders once, and a later write updates only the binding.
  • A query reader renders once on an equal result, and a later selection change still reaches it.
  • A query reader renders again on a newer live result for the same selection, and on a pending selection.
  • A streamed reader renders once when the stream completed after its HTML. It renders again for a later yielded value, and for a snapshot read whose complete changed.

Each test was seen failing against a deliberate break:

  • With the optimization disabled, the unchanged-reader, binding, query and stream tests fail.
  • Moving binding reads live fails the binding test.
  • Not comparing values fails the changed-value tests.
  • Dropping reads instead of subscribing live fails the later-write tests.
  • Ignoring snapshot metadata fails the snapshot stream test.

Risk / follow-ups

  • Bundle size. Budget-only ci(bundle-size): raise hydrate-frame budgets for unchanged adoption reads #1863 must merge first; this PR's size gate fails until then. The open perf(signals): install the public Scope surface only from createScope #1851 also rewrites the hydrate-frame budget, so whichever lands second recomputes from main.
  • Object values still re-render. A frame decodes its seed separately from the live owner, so object or array reads never match. Sharing decoded identity when the encoded value matches would extend the win to objects. That would be a separate change.
  • Lazy comparison. The comparison runs only when a committed consumer can actually move the read. Discarded hydration attempts, pending captures, retry leases and explicit beginAdoption subscribers keep the old notify path. A comparison that throws also falls back to notifying.

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 hydration adoption release and native read subscription wiring; incorrect rebasing could skip needed renders or break live updates, though tests cover unchanged/changed/query/stream/binding cases.

Overview
Hydration adoption release no longer forces every component that read a signal during hydration to render again when live state still matches the server.

On AdoptionFrameImpl.release, each historical read subscriber can be rebased via registerNativeReadRebase / rebaseNativeRead: if unchangedLiveRead finds the live value (and snapshot metadata when applicable) still matches what was presented, the native read consumer swaps its committed subscription from the historical source to the live one without scheduling a render. Changed reads—early edits, newer query results, pending selections, later stream yields, or snapshot complete changes—still notify and re-render as before.

Targeted bindings ({value$}) read through a separate historical channel (historicalBindingRead); on unchanged release those reads are dropped rather than moved, so the component body never gains a render dependency on that signal.

Docs and a patch changeset describe the behavior; new hydration/stream tests assert render counts and side effects for unchanged vs changed adoption paths.

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

trueadm and others added 2 commits October 7, 2026 21:33
…e unchanged

After a hydration commit, releasing the adopted server values notified every
Block that read a signal while hydrating, so each one rendered again in the
same task even when the live value still equalled the server value. Parents
render their children, so a section-level read rendered the whole section
twice.

Release now offers each historical read to its subscribers before notifying
them. When the consumer's committed render alone holds the read, and a live read
would present the same value, the consumer moves the read to the live node
without rendering. A snapshot read also compares status and activity. Targeted
binding reads use their own channel and are dropped, because the binding keeps
its own live subscription. Every other subscriber, and every changed read, is
notified as before.

The consumer-side move is a standalone function that hydration registers. Only
bundles that adopt native reads include it.

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 Oct 7, 2026
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 20:39
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • ❌ bundle-reachability: 3 value(s) exceed their committed budget
  • 🔴 bundle-size: 2 value(s) increased within budget
  • 🔴 bundle-reachability: 4 value(s) increased within budget

Compares 21f911d51, the merge commit's first parent with 803e44985 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 2.567 2.517 −0.0% −3.8% … +1.8% ⚪ within noise
octane-tsrx replace 6.575 6.600 +1.6% −2.9% … +5.6% ⚪ within noise
octane-tsrx add 2.692 2.675 −3.5% −3.8% … ±0.0% ⚪ within noise
octane-tsrx update 0.127 0.125 −1.8% −6.4% … −0.3% ⚪ within noise
octane-tsrx select 0.005 0.006 +1.1% −0.6% … +1.7% ⚪ within noise
octane-tsrx swap 0.034 0.035 +0.8% −1.4% … +3.6% ⚪ within noise
octane-tsrx remove 0.017 0.016 ±0.0% −3.2% … +3.5% ⚪ within noise
octane-tsrx runlots 30.300 28.992 −2.2% −7.4% … +2.3% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 −0.0% −4.5% … +2.5% ⚪ within noise
octane-tsrx clear 52.558 56.633 +4.6% +0.6% … +7.3% ⚪ within noise
octane-jsx run 4.933 4.950 −2.2% −13.0% … +8.4% ⚪ within noise
octane-jsx replace 8.142 8.033 −0.1% −5.9% … +6.7% ⚪ within noise
octane-jsx add 3.308 3.142 −0.0% −3.1% … +0.0% ⚪ within noise
octane-jsx update 0.260 0.287 +2.3% −0.3% … +5.5% ⚪ within noise
octane-jsx select 0.165 0.162 −2.9% −8.6% … +0.2% ⚪ within noise
octane-jsx swap 0.257 0.260 +1.3% −1.7% … +4.8% ⚪ within noise
octane-jsx remove 0.221 0.221 +2.2% −0.6% … +8.6% ⚪ within noise
octane-jsx runlots 51.342 51.342 +7.9% −3.2% … +16.7% ⚪ within noise
octane-jsx select_lots 3.943 2.849 −12.9% −27.1% … −2.8% ⚪ within noise
octane-jsx clear 131.767 135.808 +0.6% −9.7% … +16.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx full_fw_raw 564,583 564,614 +31 (+0.0%) 🔴
octane-tsrx full_fw_gzip 169,804 169,790 −14 (−0.0%) 🟢
octane-tsrx full_fw_brotli 142,981 142,817 −164 (−0.1%) 🟢
octane-jsx full_fw_raw 564,583 564,614 +31 (+0.0%) 🔴
octane-jsx full_fw_gzip 169,804 169,790 −14 (−0.0%) 🟢
octane-jsx full_fw_brotli 142,981 142,817 −164 (−0.1%) 🟢

54 other measured values are unchanged.

Public-import reachability bundles (bytes)

❌ 3 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").

target metric head budget over
hydrate-frame raw 366,032 365,194 +838
hydrate-frame gzip 113,311 112,948 +363
hydrate-frame brotli 96,797 96,725 +72
target metric base head Δ
hydrate-frame raw 364,886 366,032 +1,146 (+0.3%) 🔴
hydrate-frame gzip 112,823 113,311 +488 (+0.4%) 🔴
hydrate-frame brotli 96,548 96,797 +249 (+0.3%) 🔴
binding-base-ui-esbuild brotli 59,705 59,676 −29 (−0.0%) 🟢
binding-radix-esbuild gzip 69,408 69,407 −1 (−0.0%) 🟢
binding-radix-esbuild brotli 60,213 60,124 −89 (−0.1%) 🟢
binding-mantine-hooks-esbuild gzip 30,351 30,350 −1 (−0.0%) 🟢
binding-mantine-hooks-esbuild brotli 27,030 27,094 +64 (+0.2%) 🔴
binding-apollo-client-esbuild brotli 100,451 100,608 +157 (+0.2%) 🔴
binding-usehooks-ts-esbuild gzip 30,574 30,575 +1 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 27,283 27,325 +42 (+0.2%) 🔴

100 other measured values are unchanged.

trueadm added a commit that referenced this pull request Oct 7, 2026
…e raise

Main 96c4096 lowered hydrate-frame back to 364,918 / 112,855 / 96,725.
Recompute the raise from what CI measured for #1862's head (366,032 /
113,311 / 96,797) plus the standard headroom: 366,064 raw, 113,343 gzip
and 97,053 brotli.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 7, 2026
…eads (#1863)

Budget-only raise for #1862. That change lets hydration skip
rendering a native signal reader again when its live value is unchanged.
hydrate-frame, the only minimal scenario that hydrates with native signal reads,
grows by +1,146 raw, +488 gzip and +249 brotli. Each value is the current budget
plus that delta, so the raise from #1858 for #1857 is kept.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit f6b6615 into main Oct 7, 2026
8 of 24 checks passed
@trueadm
trueadm deleted the perf/adoption-release-unchanged-reads branch October 7, 2026 21:02
trueadm added a commit that referenced this pull request Oct 7, 2026
Conflicts: the 87 react-parity manifests and the user-apps-v1 manifest
record the lockfile hash, which #1860 (react-alien-signals port) changed.
pnpm sync regenerated them. The merged lockfile needs no change from
`pnpm install --lockfile-only` and still holds no TypeScript 7.0.2.

Also takes #1862 and its hydrate-frame budget raise (#1863). This branch
changes no bundled code, so its budgets stay main's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 7, 2026
With #1857 (in-place Block signal owners) and #1862 (unchanged adoption reads)
on main, this branch's hydrate-frame measures 364,278 raw, 112,866 gzip and
96,483 brotli. The budget is that measurement plus headroom: 364,310 /
112,898 / 96,616. That is below main's 366,064 / 113,343 / 97,053, so it lowers
rather than raises.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
domgan-oai pushed a commit that referenced this pull request Oct 7, 2026
…#1851)

* perf(signals): install the public Scope surface only from createScope

Owner scopes that the runtime creates for compiled signal declarations never
reach application code, yet every signal application shipped the whole public
Scope implementation: serialization, inspection, trace recording and the
imperative derived$/get/set/isPending/batch/action methods.

ScopeImpl keeps one class shape. createScope installs the public-only methods
on its prototype the first time it runs, and only a debug scope installs trace
recording. The server's native-read driver installs the read serializer, so
clients never ship it. beginAdoption stays a method: hydration resolves it
through the owner, and importing the engine from the hydration path would pull
the engine into applications without signals.

An internal OwnerScope type omits the installed members, so internal code that
reaches for one fails to typecheck.

Signal applications are 871 to 1,118 B smaller gzipped; applications without
signals are byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(signals): keep native-read serialization off the server's import path

The server's native-read driver imported the engine to install the read
serializer. That loaded the engine, and its top-level batch-hook registration,
on every server render, including applications without signals, and Node's
strip-only TypeScript loader rejects the engine's parameter property
(register-hook direct server scripts failed).

serializeRead is a ScopeImpl method again, reached through the owner as on
main, so the server path and graph.ts match main. The server-render budget
returns to main's value. Signal applications are now 489 to 652 B smaller
gzipped; applications without signals stay byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(hydration): read local scope state without the public inspect()

native-deferred-local-hook-diagnostics reached through a useSignal$ handle's
internal owner and called inspect(). Runtime-created scopes no longer carry the
public Scope surface unless the program calls createScope, and these cases
never do. Read the adoption leases and node count that inspect() reported
from the scope directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(signals): hand out whole Scopes from the public owner routes

Runtime-created owner scopes reach application code: derived$ and query$ run
authored callbacks under them, so the public currentSignalOwner() returns one,
and a host SignalOwnerEnvironment carries them. Both are typed SignalOwner,
which narrows to Scope, but without an earlier createScope the scope lacked
inspect(), get() and the other installed methods.

currentSignalOwner and installSignalOwnerEnvironment exported from
octane/signals now install the public Scope methods before an owner can
escape; the runtime keeps owner-context's engine-free versions.
octane/server's carrier must stay engine-free, so SignalOwnerEnvironment now
carries owners as SignalOwnerIdentity values: a carrier stores and returns
them but cannot narrow them to Scope. Carriers that store SignalOwner values
compile unchanged.

bundle-boundaries builds each route in its own program without createScope
(the review's currentSignalOwner probe and a carrier that calls the owner it
carries); both fail with "inspect is not a function" without this change. A
type test pins the identity-typed carrier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(bundle-size): lower the hydrate-frame budget for the lighter signal scope

hydrate-frame (added on main by #1855) hydrates signal reads, so it ships
the signal engine. Against 188d60b's sources it is 2,030 B raw, 488 B gzip
and 437 B brotli smaller with this branch's engine, and no other minimal
scenario moves. The new budget is main's budget minus that delta, because
this machine measures main's own hydrate-frame 4 B over its budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(bundle-size): re-measure hydrate-frame with #1857 and #1862 merged

With #1857 (in-place Block signal owners) and #1862 (unchanged adoption reads)
on main, this branch's hydrate-frame measures 364,278 raw, 112,866 gzip and
96,483 brotli. The budget is that measurement plus headroom: 364,310 /
112,898 / 96,616. That is below main's 366,064 / 113,343 / 97,053, so it lowers
rather than raises.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

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