Skip to content

Commit 0f5b150

Browse files
ryansolidclaude
andauthored
perf(signals): fold verdict and lane upkeep out of builds without those engines (#4418)
* perf(signals): fold verdict and lane upkeep out of builds without those engines Hello world (compiled floor) 10,059 -> 9,967 B brotli. The verdict engine's CONFIG_ASYNC upkeep, its CONFIG_VERDICT re-derive and flag checks, and recompute's pass-lane seat and restores are guarded on the engines' hooks, which the minifier folds when nothing installs them. CONFIG_VERDICT is only ever set by the verdict engine and passLane only by the lane engine, so the guards change no behavior in any build. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): re-record the three verdict scenarios after the floor trim isPending/latest 11.03 -> 11.05 KB (30,407 B), compiled live page 42.61 -> 42.62 KB (125,165 B), live + router 48.29 -> 48.31 KB (142,427 B), from this PR's CI size run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent 9545058 commit 0f5b150

5 files changed

Lines changed: 51 additions & 36 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Smaller core for apps without `isPending`/`latest` or optimistic lanes: the verdict engine's async-memo bookkeeping, its re-derive checks and the pass-lane seat now sit behind the engines' hooks, so a bundle that never installs them folds that code away (hello world −92 B brotli). No behavior change.

‎packages/signals/src/core/async.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
316316
// A19: a verdict reader holds no pending of its own (it was re-derived
317317
// when the source went pending, `propagateStatus`), and a landing
318318
// equal to the committed value notifies nobody — the source settling
319-
// is its verdict changing: it runs again.
320-
return node._config & CONFIG_VERDICT && enqueueSub(node);
319+
// is its verdict changing: it runs again. (Verdict readers exist only
320+
// with the verdict engine installed.)
321+
return holdWorkHook && node._config & CONFIG_VERDICT && enqueueSub(node);
321322
visited.add(node);
322323
node._time = clock;
323324
const remaining = node._x?._pendingSources?.values().next().value;
@@ -431,7 +432,7 @@ export function handleAsync<T>(
431432
if (!thenable && !iterator) {
432433
if (el._x !== null) {
433434
el._x._inFlight = null;
434-
el._config &= ~CONFIG_ASYNC;
435+
if (holdWorkHook) el._config &= ~CONFIG_ASYNC;
435436
}
436437
// A sync landing is the first real answer for a loadingValue node.
437438
el._loading = false;
@@ -469,7 +470,9 @@ export function handleAsync<T>(
469470
ext(el)._inFlight = result as PromiseLike<T> | AsyncIterable<T>;
470471
// D-25 (verdict.ts `holdWork`): an async memo whose answering pass opened
471472
// no verdict window of its own (`markVerdictReader` clears the bit).
472-
if (!(el._flags & REACTIVE_WINDOW)) el._config |= CONFIG_ASYNC;
473+
// Kept by the verdict engine alone (`holdWorkHook`): a build without it
474+
// folds the bit's upkeep away.
475+
if (holdWorkHook && !(el._flags & REACTIVE_WINDOW)) el._config |= CONFIG_ASYNC;
473476
// The question this flight answers (A18 provenance, lanes.ts): the action
474477
// whose slice asked it; mainline is always the current question.
475478
el._x!._q = question || MAINLINE_QUESTION;
@@ -1005,7 +1008,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
10051008
// (F-9), and asks its next question once, at the landing (#4397).
10061009
if (
10071010
sub._config & CONFIG_REDERIVE ||
1008-
(sub._config & CONFIG_VERDICT && !(pendingSource && holdWorkHook!(sub, el))) ||
1011+
(holdWorkHook && sub._config & CONFIG_VERDICT && !(pendingSource && holdWorkHook(sub, el))) ||
10091012
(status === STATUS_PENDING && link._gen !== sub._depGen)
10101013
) {
10111014
enqueueSub(sub);

‎packages/signals/src/core/core.ts‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import {
138138
laneStageHook,
139139
laneSeamsHook,
140140
laneServedHook,
141+
holdWorkHook,
141142
laneWriteHook,
142143
observeFlightHook,
143144
wireExternalSourceHook
@@ -346,27 +347,27 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
346347
// Restored at the end, after this pass's staging and runs have been
347348
// routed.
348349
// Lanes exist only with the lane engine installed (`laneStageHook`): a
349-
// bundle without it seats every pass on mainline, and folds the seat away.
350+
// bundle without it seats every pass on mainline (`passLane` is never set)
351+
// and folds the seat, and its restores, away.
350352
const prevLane = passLane;
351353
// The mount a first pass belongs to: its creator's lane, or the one its
352354
// creator's own mount came from — a render effect a verdict lane's mount's
353355
// content creates is that mount's too (#4166). Lanes only, like the seat.
354356
const prevMount = laneRoot;
355357
const mount = laneStageHook && (laneRoot = create && (prevLane || prevMount));
356-
setPassLane(
357-
!laneStageHook
358-
? null
359-
: (el._flags & REACTIVE_LANE_DIRTY ||
360-
(el._config & (CONFIG_OVERRIDE | CONFIG_GUESS)) === CONFIG_OVERRIDE) &&
361-
el._x?._transaction?._lane
358+
if (laneStageHook)
359+
setPassLane(
360+
(el._flags & REACTIVE_LANE_DIRTY ||
361+
(el._config & (CONFIG_OVERRIDE | CONFIG_GUESS)) === CONFIG_OVERRIDE) &&
362+
el._x?._transaction?._lane
362363
? el._x._transaction
363364
: // Loose `!=`: false with no creator lane (undefined == null).
364365
create &&
365366
prevLane?._parent!._verdict != prevLane &&
366367
(creatorPass(context)?._flags as number) & REACTIVE_RECOMPUTING_DEPS
367368
? prevLane
368369
: null
369-
);
370+
);
370371
// Attribution hook: fired before this run touches the dep list — `_deps`
371372
// still holds the previous run's links (the subscriptions that could have
372373
// triggered this run, and the baseline for the engine's subscription diff).
@@ -560,7 +561,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
560561
if (!selfRegistered && !isAsyncResult) {
561562
if (el._x !== null) {
562563
el._x._inFlight = null;
563-
el._config &= ~CONFIG_ASYNC;
564+
if (holdWorkHook) el._config &= ~CONFIG_ASYNC;
564565
}
565566
// A sync (non-object) return is the first real answer; async-shaped
566567
// results clear inside handleAsync at their own landing points, and a
@@ -575,6 +576,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
575576
if (el._statusFlags !== 0 || el._x !== null) clearStatus(el, create);
576577
} catch (e) {
577578
const notReady = e instanceof NotReadyError;
579+
// An error answers, and so does a loading window's unready read (D-25,
580+
// verdict.ts `holdWork`): no flight is its own. A pass left pending
581+
// keeps the last answer's. (Kept by the verdict engine alone.)
582+
if (holdWorkHook && (!notReady || el._loading)) el._config &= ~CONFIG_ASYNC;
578583
if (notReady && el._loading) {
579584
// Loading window with an unready sync dependency: register for the
580585
// source's settle (the settlePendingSource walk runs off
@@ -583,11 +588,8 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
583588
// keeps serving. If the
584589
// node is currently errored the error stays the answer until this
585590
// retry can actually run.
586-
el._config &= ~CONFIG_ASYNC;
587591
parkLoadingWindow(el, e as NotReadyError);
588592
} else {
589-
// An error answers (D-25, verdict.ts `holdWork`): no flight is its own.
590-
if (!notReady) el._config &= ~CONFIG_ASYNC;
591593
// D-41: a pass of a held node, or one that read a staging of this
592594
// flush, stages its error (`stageError`).
593595
if (notReady || !(stagedErr = stageError(el, e, true))) {
@@ -642,7 +644,9 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
642644
// that does (`read`): a pass that did neither (REACTIVE_PROBED, the same
643645
// bit) is an ordinary derivation again. Its async posture is the
644646
// verdict engine's to keep (CONFIG_ASYNC, verdict.ts `holdWork`, D-25).
645-
el._config = (el._config & ~CONFIG_VERDICT) | (el._flags & REACTIVE_PROBED);
647+
// (Only the verdict engine probes: without it the line folds away.)
648+
if (observeFlightHook)
649+
el._config = (el._config & ~CONFIG_VERDICT) | (el._flags & REACTIVE_PROBED);
646650
// REACTIVE_DISPOSED survives too (#3621): the pass may have disposed its
647651
// own owner (a memo calling its root's `dispose()`, a cleanup doing so
648652
// #3601/#3606), and `disposeChildren` set the flag on this node
@@ -684,7 +688,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
684688
if (el._x !== null) el._x._inFlight = null;
685689
if (__OBSERVE__ && attrHooks !== null)
686690
attrHooks.recomputeEnd(el, create, false, false, false, false);
687-
setPassLane(prevLane);
691+
if (laneStageHook) setPassLane(prevLane);
688692
return;
689693
}
690694
// The lane this pass is work of, if any: its seat (the node's, its
@@ -960,7 +964,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
960964
// Lane work is the lane's to reveal (its seam), not this flush's commit.
961965
if (lane === null) queuePendingNode(el);
962966
}
963-
setPassLane(prevLane);
967+
if (laneStageHook) setPassLane(prevLane);
964968
// Missed-wake reschedule (see the finally above): values this pass read
965969
// before the nested commit are stale, so run again now that the heap will
966970
// accept the node. Equality gates stop same-value landings from cascading,
@@ -1989,7 +1993,9 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
19891993
// it probed inline: it reads held values as the screen and shows the
19901994
// verdict now. Not an effect: a render effect is a frame reader
19911995
// already, and a user effect's posture is its own reads'.
1992-
if (!(c as any)._type) (c as Computed<any>)._flags |= owner._config & CONFIG_VERDICT;
1996+
// (A verdict memo exists only with the verdict engine installed.)
1997+
if (observeFlightHook && !(c as any)._type)
1998+
(c as Computed<any>)._flags |= owner._config & CONFIG_VERDICT;
19931999
}
19942000
}
19952001
// L2, as in the fast block above (tracked or not). A node born into the
@@ -2052,23 +2058,21 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
20522058
// — unless the flight committed beneath inputs already on screen
20532059
// (`observeFlight`), or the reader was born into the flight's transaction
20542060
// (#4010): it has no screen, and waits on the flight with its frame.
2061+
// (A lane, and a verdict reader, exist only with their engines installed —
2062+
// the verdict engine imports the lane engine: without it the test folds.)
20552063
if (
2064+
laneStageHook &&
20562065
owner._statusFlags & STATUS_PENDING &&
20572066
!committed &&
20582067
!(el._config & CONFIG_OVERRIDE) &&
20592068
!(owner._statusFlags & STATUS_UNINITIALIZED)
20602069
) {
20612070
// A reader with no committed value yet sees the flight pending: a
20622071
// boundary a lane mounts shows its fallback (A29's boundary exemption).
2063-
// (A lane, and a verdict reader, exist only with their engines installed.)
2064-
if (
2065-
laneStageHook &&
2066-
passLane !== null &&
2067-
!((c as Computed<any> | null)?._statusFlags! & STATUS_UNINITIALIZED)
2068-
)
2072+
if (passLane !== null && !((c as Computed<any> | null)?._statusFlags! & STATUS_UNINITIALIZED))
20692073
committed = true;
2070-
else if (observeFlightHook && c !== null && c._config & CONFIG_VERDICT)
2071-
committed = observeFlightHook(c as Computed<any>, owner);
2074+
else if (c !== null && c._config & CONFIG_VERDICT)
2075+
committed = observeFlightHook!(c as Computed<any>, owner);
20722076
}
20732077
if (owner._statusFlags & STATUS_PENDING && !committed) {
20742078
// A reader landing on a pending node throws; an untracked read of an

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ export function reruns(u: Transaction): unknown {
12171217
(s?._statusFlags ?? STATUS_ERROR) & STATUS_ERROR)
12181218
)
12191219
continue;
1220-
if (r._flags & REACTIVE_FRAME_READ || r._config & CONFIG_VERDICT) {
1220+
if (r._flags & REACTIVE_FRAME_READ || (observeFlightHook && r._config & CONFIG_VERDICT)) {
12211221
frame ||= (r as any)._type;
12221222
// A lane's reveal leaves the mark to the transaction: a reader that
12231223
// also read a held node as committed (`staleReader`) still observes

0 commit comments

Comments
 (0)