Skip to content

Commit a237699

Browse files
committed
perf(createDeferred): the derive carries its family, the walk lives in the mark core
The projection derive now carries `fam` (the object) instead of a closure, and the repoll iterates the family's live nodes itself. That moves the iteration off the store floor into affects-marks.ts, which only createDeferred and affects() load: -12 B minified on every store scenario. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01S2HrYgWeGJX6hKw7bD5LQN
1 parent 492a84b commit a237699

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎packages/signals/docs/create-deferred.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ supersedes that PR.
443443
a mark whose lifetime is the flight, not counted while a `refresh()`
444444
re-ask is in flight. Coverage is the probe-time dependency walk, which
445445
now hops a store slot to its family's derive; the repoll reaches a derived
446-
store's leaf readers through the derive's `family`.
446+
store's leaf readers through the derive's `fam`.
447447
- **Truth readers** (`refresh`'s waiter, `until`): `watch` throws
448448
`NotReadyError` for a deferred flight the value derives from
449449
(`GlobalQueue._lagging`), so they park; the mark's repoll at the landing

‎packages/signals/src/affects-marks.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ export function repoll(
4646
seen.add(sub);
4747
if (sub._config & readers) enqueueSub(sub);
4848
if (!(sub as any)._type) repoll(sub, seen, readers);
49-
// A derived store's derive: its leaves' readers derive from it too.
50-
(sub as any).family?.((n: Marked) => repoll(n, seen, CONFIG_VERDICT));
49+
// A derived store's derive: its leaves' readers derive from it too
50+
// (store/projection.ts; a live target's property, has and keys nodes).
51+
const fam = (sub as any).fam;
52+
if (fam)
53+
for (const t of fam.live)
54+
for (const o of [t.n, t.h, { k: t.k, d: t.dk }])
55+
if (o) for (const k of Reflect.ownKeys(o)) o[k] && repoll(o[k], seen, CONFIG_VERDICT);
5156
}
5257
}
5358

‎packages/signals/src/store/projection.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function createProjectionInternal<T extends object = {}>(
343343
fam.node = node;
344344
// The derive's leaves are not its dependents: a mark's repoll
345345
// (affects-marks.ts) reaches their readers through this.
346-
(node as any).family = (fn: (n: Signal<any>) => void) => forEachFamilyNode(fam, fn);
346+
(node as any).fam = fam;
347347
return { store, node } as { store: Refreshable<Store<T>>; node: Computed<void | T> };
348348
}
349349

0 commit comments

Comments
 (0)