Repository navigation
perf(signals): install the public Scope surface only from createScope - #1851
Conversation
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]>
Benchmark report🟢 No budget breaches, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)
108 other measured values are unchanged. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 41eeeea | Commit Preview URL Branch Preview URL |
Oct 07 2026, 06:10 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| 🔵 In progress View logs |
octane-website | b684fb9 | Oct 07 2026, 08:08 PM |
…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]>
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]>
domgan-oai
left a comment
There was a problem hiding this comment.
Recommendation: do not merge this head yet. There is one reproducible public API regression (inline). The bundle-size design is otherwise contained: retaining native-read serialization/adoption on the common scope and splitting cold public methods is defensible, and I found no separate internal SSR/hydration defect.
Validation: all 32 reported current-head checks are green (including CI tests/parity/typecheck and PR bench); git diff --check passes. I ran the same renderer-free probe on the exact base 83eaaf4 and head 41eeeea, using Node TypeScript transform and the lock-matched alien-signals 3.2.0: base returned probe, head threw TypeError. This is a direct source/API reproduction, not a production bundler measurement. I could not independently rerun the full workspace/bundle suite: the isolated checkout has no dependencies and its pinned pnpm was unavailable from the configured registry. The exact quoted size savings remain the PR author's measurements.
Please fix the exposed owner contract and cover the no-createScope case, then rerun CI. GitHub also currently reports BEHIND / REVIEW_REQUIRED, so repository merge requirements still apply.
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]>
…nal 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]>
|
Following up on the benchmark report:
🤖 Posted by Claude Code |
…ighter-signal-scope # Conflicts: # benchmarks/bundle-size/minimal-budgets.json
…ighter-signal-scope # Conflicts: # benchmarks/bundle-size/minimal-budgets.json
…ighter-signal-scope # Conflicts: # benchmarks/bundle-size/minimal-budgets.json
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]>
…ighter-signal-scope # Conflicts: # benchmarks/bundle-size/minimal-budgets.json
…he trace-retention guard (#1916) #1907 removed every committed budget gate but missed one. The chromium browser lane runs view-transitions/effect-cleanup.mjs on every PR, and it failed when total or idle-extra function calls exceeded effect-cleanup-budget.json (measured + 32 calls). Delete that file and both ceiling checks. The run still requires zero stageTeardown entries, the shared lifecycle snapshots, completed native primers and unchanged provenance hashes, and it still reports total_calls and idle_extra_calls. #1907 also deleted the scoped-signals-trace guard (wrapped-max-budget over unfilled-max-budget, trace_event, 1.5x) only because its reference name ends in -budget. That name refers to the 10,000-event trace retention limit; the guard compares two configurations timed in the same run. Restore it verbatim. run-trace.mjs has not produced numbers since #1851, because it built ScopeImpl with the old (key, options) constructor and #1851 installs trace recording and inspect() only through createScope. Build scopes through createScope so the suite runs and the restored guard is evaluated again. Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
This is part of the size work tracked in #1801. Apps that use signals are 0.49 to 0.65 kB smaller gzipped. Apps without signals are byte-identical. The
ScopeAPI is unchanged. One public type changes:SignalOwnerEnvironmentcarries owners asSignalOwnerIdentity(see below), so the changeset isminor.The problem. The runtime creates owner scopes for compiled
signal$,derived$,query$anduseSignal$declarations. Most apps never hold one. But every app with signals still shipped the whole publicScopeimplementation as methods onScopeImpl:derived$,get,set,isPending,batchandactionmethods.Bundlers never remove class methods, so even an app that never calls
createScopepaid for all of it.What changed.
ScopeImplkeeps one class shape, so the hot read and write paths are unchanged.installPublicScopeputsserialize,inspect,derived$,get,set,isPending,batchandactionon the prototype. Runtime-created scopes come fromcreateOwnerScope,createSeededOwnerScopeandcreateLocalScope.derived$andquery$run authored callbacks under them.createScopeand theoctane/signalsexports ofcurrentSignalOwnerandinstallSignalOwnerEnvironment(signals/public-owner.ts) callinstallPublicScopebefore an owner can escape. Only apps that use them pay.owner-context.ts.octane/serverexportsinstallSignalOwnerEnvironmentengine-free, and app-core installs it for every SSR request, so it cannot install the methods.SignalOwnerEnvironmentnow carries owners asSignalOwnerIdentity. A carrier stores and returns them but cannot narrow them toScope.SignalOwnerIdentityis a member ofSignalOwner, so carriers that storeSignalOwnervalues (app-core, the tests and benchmarks here) compile unchanged.createScope({ debug })scope installs it.trace()keeps its existingtraceLimitcheck.serializeReadandbeginAdoptionstay methods. Server native reads serialize internal owner scopes, and hydration adopts seeds into them.native-read-server.ts,native-read-seeds.ts) load in apps without signals, so neither can import the engine.native-read-seeds.tsgrew the React-parity kitchen sink by 8.5 kB gzip.register-hook.test.ts). The second commit puts the method back, sograph.tsandnative-read-server.tsmatch main.signal$stays a method.useSignal$calls it on its local scope. The facade'sisScopeguard also identifies a scope by it.OwnerScopetype omits the installed members. Internal code that calls one of them on a runtime-created scope now fails to typecheck, instead of failing only in apps that never callcreateScope.Measurements
Framework bytes, Vite + oxc production builds, on aaac26c and then on this branch:
signal$(createRoot)useSignal$onlyquery$signal$query$hydrate-frame(added on main by perf(octane): keep the transition and hidden-Activity graphs out of Suspense-only bundles #1855) is the only committed scenario that ships the signal engine. It is about 2 kB raw and 0.5 kB gzip smaller with this PR.hydrate-frameat 364,278 raw / 112,866 gzip / 96,483 brotli, the same here and on CI.budget-raises.mjsreports no raise.benchmarks/scoped-signals/run.mjs 15 --sizes=100,1000against an archive of the base commit (--source-root/--source-ref). It alternated base and head for 3 rounds and covered 65 operation timings. The head/base geometric mean was 0.984. Every per-operation difference was inside the run-to-run spread.createScopescopes, so it also exercises the prototype-installed methods.Validation
pnpm format:files:checkon the changed files (repo-widepnpm format:checknot run)pnpm typecheck(not run repo-wide).octane-tscoverpackages/octane/tsconfig.json, itstypetestsandtypetests/signals-engine-nodeconfigs, andpackages/app-core/tsconfig.typecheck.jsonis clean, as ispnpm typecheck:files.pnpm test(not run locally; left to CI)octane-signals-node: 273/273octane-signals,octane-signals-prodandoctane-signals-strong: 327/327 eachoctane-signals-profile: 3/3octaneand 320/320 inoctane-prodOwnerScopetype change. That change touches only types, and the production bundles match byte for byte.octane-signals-node(273/273),register-hook.test.ts(3/3), the SSR-seed, streamed-cancellation and native-read files (16/16), and the regression test.benchmarks/scoped-signals/bundle-boundaries.test.mjs:compiled signal declarations omit the public Scope surface until createScope.createScope. It checksderived$,get,set,action,batch,isPending,serialize,inspectand trace recording, and that owner scopes still work before and after the methods are installed.origin/mainsource with "A program without createScope retained the public Scope surface."bundle-boundaries.test.mjsbuilds each route in its own program withoutcreateScope. The review'scurrentSignalOwnerprobe returns'probe', and a carrier that calls the owner it carries seesinspect().inspect is not a function.typetests/signal-owner-environment.test-d.tspins the identity-typed carrier. Its@ts-expect-errorfails against main'sSignalOwnersignature.event-signal-owner,stable-event-authority,hydration/signal-instance-identityandhydration/document-signal-owner(249/249), app-corerequest-signal-lifetime(3/3), andpublished-errors.test.mjsagainst a localdistbuild (3/3).node benchmarks/bundle-size/run-minimal.mjs --budgets --ratchetandnode benchmarks/bundle-size/run.mjs --budgets --ratchet octane-tsrx octane-jsxwithBUDGET_BASE=origin/mainRisk / follow-ups
serializeReadmethod.createScopecall changesScopeImpl.prototype. V8 then resets the inline caches for scope method lookups once. If an app callscreateScopeonly after it has warmed up (for example, from a lazily loaded route), that costs one re-warm.getSignalScopeandOptimisticDescriptornow use the internalOwnerScopetype. The public routes that return an owner install theScopemethods first.ownerand callsinspect()(or another installed method) now throwsTypeErrorunless the program has calledcreateScope.native-deferred-local-hook-diagnostics.test.tsdid this in itsuseSignal$cases. The third commit makes it read the leases and node count from the scope directly. No other test, package, example or site code does this.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes signal runtime initialization and owner typing; apps that relied on calling public Scope methods on runtime-created owners without createScope will throw at runtime.
Overview
Defers shipping the full public
ScopeAPI until an app actually needs it. Runtime owner scopes for compiledsignal$/derived$/query$/useSignal$no longer always carryserialize,inspect, imperativeget/set/batch/action, and related code;installPublicScopeattaches those methods onScopeImpl.prototypeonly whencreateScoperuns or whencurrentSignalOwner/installSignalOwnerEnvironmentare imported fromoctane/signals(via newpublic-owner.ts). Internal code usesOwnerScopeandcreateOwnerScope/createSeededOwnerScopeso missing the public surface is a type error; debug trace recording installs only forcreateScope({ debug }).SignalOwnerEnvironmentnow passesSignalOwnerIdentityso SSR/host carriers (e.g.octane/server) cannot narrow owners toScopeand callinspect()—a minor public typing change. Bundle budgets forhydrate-framedrop ~0.5 kB gzip; a bundle-boundaries regression test asserts compiled-declaration bundles omit inspection-related code untilcreateScope.Reviewed by Cursor Bugbot for commit 5ee09e5. Bugbot is set up for automated code reviews on this repo. Configure here.