Skip to content

Commit e8d6c49

Browse files
committed
fix(signals): fold the #4540 staged check into the existing staged local
The first cut read `_pendingValue` again at the top of recompute and cost +8 B minified on every core row. The equality gate already reads it for compareValue and the effect gate reads it a third time; one `unstaged` local now serves all three, and the uninitialized term checks it at the gate. Core rows are back to +0 B minified, and the gate does one fewer property load per pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 4fa4146 commit e8d6c49

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
520520
if (__DEV__) clearSignals(el);
521521
}
522522

523-
// #4540: a first value already staged this frame is the slot this pass
524-
// publishes to (INV-11): a re-pass equal to it changes nothing, though the
525-
// node stays uninitialized until the commit.
526-
const wasUninitialized =
527-
el._statusFlags & STATUS_UNINITIALIZED && el._pendingValue === NOT_PENDING;
523+
const wasUninitialized = !!(el._statusFlags & STATUS_UNINITIALIZED);
528524
// Capture both error and pending status before the compute clears them.
529525
// A conditional can drop its pending source and recover to an unchanged
530526
// value, leaving blocked dependents outside that source’s settle walk.
@@ -794,19 +790,22 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
794790
// publishes to — the staged `_pendingValue` when staged; a lane node's
795791
// lane value (a node entering the lane this pass has none yet — its
796792
// committed value, `laneStage` having voided a frame staging).
797-
const compareValue =
798-
el._pendingValue !== NOT_PENDING
799-
? el._pendingValue
800-
: el._config & CONFIG_OVERRIDE && el._x!._lane !== NOT_PENDING
801-
? el._x!._lane
802-
: el._value;
793+
const unstaged = el._pendingValue === NOT_PENDING;
794+
const compareValue = !unstaged
795+
? el._pendingValue
796+
: el._config & CONFIG_OVERRIDE && el._x!._lane !== NOT_PENDING
797+
? el._x!._lane
798+
: el._value;
803799
// A throwing comparator is contained inside `isSame` (A3, #2837; #4111).
804800
// A pass replacing an error this node staged is a new answer, even the
805801
// committed value (D-41: a recovery equal to the last good value is a
806802
// change): the slot it publishes to held the error, and the readers that
807803
// derived from it — `latest()` throws it — re-derive (#4403).
804+
// A first value already staged this frame is that slot too: a re-pass
805+
// equal to it changes nothing, though the node stays uninitialized until
806+
// the commit (#4540).
808807
const valueChanged =
809-
(!isEffect && !!wasUninitialized) ||
808+
(!isEffect && wasUninitialized && unstaged) ||
810809
!!el._x?._shownError ||
811810
!!replaced ||
812811
!isSame(el, compareValue, value);
@@ -834,7 +833,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
834833
Object.is((el as any)._prevValue, value)
835834
) &&
836835
// A re-staging pass owes no run: the commit replays the effect (#3802).
837-
el._pendingValue === NOT_PENDING
836+
unstaged
838837
) {
839838
(el as any)._modified = !el._x?._error;
840839
// Reuse one bound runner per effect — runEffect no-ops on a stale

0 commit comments

Comments
 (0)