Skip to content

Commit 149b80c

Browse files
committed
perf(signals): verdict reads test presence, not null, to pay for #4341
The size gate failed on the page scenarios once merged with next: the #4341 walk cost +29 B minified on the live page and +66/+67 B on the compiled live page and the live + router page. Those two split their eager graph into an entry and a hoisted shared chunk (web.js), with verdict.ts in the entry and core.ts and constants.ts in web.js. So the walk's `creatorPass` reference and its unfolded REACTIVE_STAGED_READ became two new cross-chunk import/export pairs, and the extra names push other aliases to two letters. verdict.ts compared object-or-null slots (`c`, `passLane`, `flushTransaction`, `t._verdict`), `_fn` and `GlobalQueue._marked` against null/undefined. It now tests their truthiness, or uses optional calls/chains. No behavior change: none of these slots holds a falsy object. Net against next: -86 B minified on isPending/latest and the live page, -48 B on the compiled live page, -49 B on live + router. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent c9d4b8f commit 149b80c

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function watchVerdict(c: Computed<any>, unanswered = false): void {
8484
* does not rescue it: its result shows at the landing, re-derived). A lane
8585
* read, for `recompute`'s tail (REACTIVE_LANE_READ). */
8686
function route(c: Computed<any>, t: Transaction): void {
87-
if (passLane === null && !(c._flags & (REACTIVE_JOINED | REACTIVE_STAGED_READ)))
87+
if (!passLane && !(c._flags & (REACTIVE_JOINED | REACTIVE_STAGED_READ)))
8888
setPassLane(verdictLane(t));
8989
c._flags |= REACTIVE_LANE_READ;
9090
}
@@ -170,7 +170,7 @@ function provisionalVerdict(c: Computed<any>, notFinal: boolean): void {
170170
verdictRead(c, flushTransaction!);
171171
return;
172172
}
173-
if (flushTransaction !== null) {
173+
if (flushTransaction) {
174174
if (notFinal) probeFound = true;
175175
verdictRead(c, flushTransaction);
176176
if (c._flags & REACTIVE_STAGED_READ) watchVerdict(c);
@@ -225,7 +225,7 @@ function heldNotFinal(owner: Computed<any>): boolean {
225225
function pendingVerdict(c: Computed<any> | null, el: Computed<any>): void {
226226
if (el._statusFlags & STATUS_UNINITIALIZED) return;
227227
if (probing && !quietPending(el)) probeFound = true;
228-
if (c !== null && tracking) {
228+
if (c && tracking) {
229229
if (el._config & CONFIG_HELD) verdictRead(c, txOf(el));
230230
else if (globalQueue._running) provisionalVerdict(c, false); // decided above
231231
}
@@ -345,7 +345,7 @@ function staged(el: Signal<any> | Computed<any>): unknown {
345345
function heldLatest(el: Signal<any> | Computed<any>, c: Computed<any> | null): unknown {
346346
const u = unflushedValue(el);
347347
if (u === NOT_PENDING) return staged(el);
348-
if (c !== null) markLateLinker(c);
348+
if (c) markLateLinker(c);
349349
return u;
350350
}
351351
/** The verdict windows' read — `latest(fn)` and `isPending(fn)` — in one
@@ -371,11 +371,11 @@ function heldLatest(el: Signal<any> | Computed<any>, c: Computed<any> | null): u
371371
* - an errored derivation throws for every reader (#2897). */
372372
function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null): unknown {
373373
const owner = el as Computed<any>;
374-
const owned = c !== null && !(c._config & CONFIG_CHILDREN_FORBIDDEN);
374+
const owned = !!c && !(c._config & CONFIG_CHILDREN_FORBIDDEN);
375375
const tracked = owned && tracking;
376-
if (c !== null && tracking) {
376+
if (c && tracking) {
377377
link(el, c);
378-
if (owner._fn !== undefined) {
378+
if ((el as any)._fn) {
379379
// A31: the pulled memo's pass is its own, not the probe's — it reads
380380
// outside the window, and the probe's read below answers for what
381381
// the pass produced.
@@ -388,9 +388,9 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
388388
// final by declaration — the value itself is read as below. The verdict is
389389
// display-ahead like any: in a transaction's flush (the declaring action's
390390
// body) the reader is its verdict lane's, not a staging the frame parks.
391-
if (probing && GlobalQueue._marked !== undefined && GlobalQueue._marked(owner)) {
391+
if (probing && GlobalQueue._marked?.(owner)) {
392392
probeFound = true;
393-
if (tracked && flushTransaction !== null) verdictRead(c!, flushTransaction);
393+
if (tracked && flushTransaction) verdictRead(c!, flushTransaction);
394394
}
395395
if (
396396
el._config & CONFIG_OVERRIDE &&
@@ -438,9 +438,8 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
438438
tracked &&
439439
!probing &&
440440
(c as any)._type === EFFECT_RENDER &&
441-
passLane === null &&
442-
t._verdict !== null &&
443-
t._verdict._held &&
441+
!passLane &&
442+
t._verdict?._held &&
444443
flushTransaction !== t
445444
) {
446445
staleReader(c!, t._verdict);
@@ -452,7 +451,7 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
452451
// An action body reading another transaction's proposal derives
453452
// from it: the two settle as one (A15; posture C, 2026-09-15). An
454453
// untracked read elsewhere has no transaction to entangle.
455-
if (!tracked && flushTransaction !== null && !globalQueue._running) joinFuture(txOf(el));
454+
if (!tracked && flushTransaction && !globalQueue._running) joinFuture(txOf(el));
456455
return heldLatest(el, tracked ? c : null);
457456
}
458457
return el._value;
@@ -481,7 +480,7 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
481480
// reader derived from the flushed world runs again in the carrying
482481
// flush.
483482
if (globalQueue._running) return staged(el);
484-
if (c !== null) markLateLinker(c);
483+
if (c) markLateLinker(c);
485484
}
486485
return el._value;
487486
}
@@ -493,10 +492,10 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
493492
// As `read()`: an untracked read of a pending node still re-runs its
494493
// reader when the node settles (a projection's pull reads its firewall
495494
// untracked, store/store.ts).
496-
if (c !== null && !tracking && !spectating && el !== c) link(el, c);
495+
if (c && !tracking && !spectating && el !== c) link(el, c);
497496
throw owner._x?._error;
498497
}
499-
if (owner._fn !== undefined && owner._statusFlags & STATUS_ERROR) throw owner._x!._error;
498+
if ((el as any)._fn && owner._statusFlags & STATUS_ERROR) throw owner._x!._error;
500499
return el._value;
501500
}
502501

0 commit comments

Comments
 (0)