Skip to content

Commit 6cc4cb3

Browse files
perf(signals): store first-read diet — probe once, look up once, cache the first wrap
The get trap's accessor probe verdict threads to getNode (accKnown) so a first tracked read scans the descriptor once, not twice; the trap's second node-map lookup is hoisted onto the hot-path's; serveDataKey captures the node it creates so the wrap-cache branch populates px/pxv at read #1. Suites green (signals 1461 / web 667 / solid 580). dbmon mount min 6.80 -> 6.50 ms; get self −19%; getNode off the top-cost list. Co-authored-by: Cursor <[email protected]>
1 parent 1946939 commit 6cc4cb3

3 files changed

Lines changed: 64 additions & 16 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+
Store first-read diet: the get trap's accessor probe verdict threads through to node creation (one descriptor scan per first read, not two), the trap's duplicate node-map lookup is hoisted, and the first tracked read populates the wrap cache so the second read skips wrapNext. dbmon mount min −4%, get-trap self-time −19%.

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,16 @@ setSlotUnobserved((node: any): void => {
248248
}
249249
});
250250

251-
export function getNode(target: StoreNextTarget, key: PropertyKey, current: any): Signal<any> {
251+
export function getNode(
252+
target: StoreNextTarget,
253+
key: PropertyKey,
254+
current: any,
255+
// First-read dedupe (create-floor slice 2): the get trap probes
256+
// accessor-ness right before creating the node — pass the verdict through
257+
// so creation skips the second descriptor scan. -1 = unknown (other
258+
// callers), 0/1 = probed.
259+
accKnown: -1 | 0 | 1 = -1
260+
): Signal<any> {
252261
const nodes = (target.n ??= Object.create(null));
253262
let node: Signal<any> | undefined = nodes[key];
254263
if (node === undefined) {
@@ -270,7 +279,7 @@ export function getNode(target: StoreNextTarget, key: PropertyKey, current: any)
270279
// Accessor-ness resolved ONCE per node (no per-object descriptor
271280
// scan on reads): accessor keys serve through Reflect.get with the
272281
// proxy receiver.
273-
isOwnAccessor(target.pb ?? target.v, key),
282+
accKnown === -1 ? isOwnAccessor(target.pb ?? target.v, key) : accKnown === 1,
274283
(target.fam?.node as any) ?? undefined
275284
));
276285
// Attribution-only: name store property nodes by path segment so
@@ -1392,7 +1401,8 @@ function serveDataKey(
13921401
key: PropertyKey,
13931402
backingValue: any,
13941403
src: Record<PropertyKey, any>,
1395-
node?: Signal<any>
1404+
node?: Signal<any>,
1405+
accKnown: -1 | 0 | 1 = -1
13961406
): any {
13971407
const chained = target.ch && src === target.v;
13981408
let v = backingValue;
@@ -1441,7 +1451,9 @@ function serveDataKey(
14411451
v = nodeValue(node, backingValue);
14421452
}
14431453
} else if (getObserver() !== null) {
1444-
readNode(getNode(target, key, backingValue));
1454+
// First tracked read: create + link, and let the wrap-cache branch
1455+
// below populate px/pxv so read #2 skips wrapNext (slice 2).
1456+
readNode((node = getNode(target, key, backingValue, accKnown)));
14451457
}
14461458
}
14471459
// Shallow stores serve data raw; store-proxy slots get boundary wrappers.
@@ -1546,8 +1558,11 @@ const traps: ProxyHandler<StoreNextTarget> = {
15461558
// tracked read of a present data key — the dbmon/uibench effect re-read
15471559
// shape. Skips serveDataKey's frame, the FORCE compare (only accessor
15481560
// keys ever hold the sentinel), and isWrappable for primitives.
1561+
// ONE node-map lookup serves this block and the accessor probe below
1562+
// (nothing between them creates nodes).
1563+
const node0 = target.n?.[key as any];
15491564
if (target.ch === false && writeScopes === null) {
1550-
const nodeH = target.n?.[key as any];
1565+
const nodeH = node0;
15511566
if (nodeH !== undefined && (nodeH as any).acc !== true && getObserver() !== null) {
15521567
let nv = readNodeFast(nodeH);
15531568
if (nv === READ_SLOW) nv = readNode(nodeH);
@@ -1601,15 +1616,21 @@ const traps: ProxyHandler<StoreNextTarget> = {
16011616
// absent-key/accessor subscriptions for every store read during any
16021617
// derive, leaving nested projections permanently dependency-less when
16031618
// their sources hadn't materialized yet (#3037).
1604-
const node0 = target.n?.[key as any];
1619+
// First-read dedupe (create-floor slice 2): remember the probe verdict —
1620+
// node creation downstream reuses it instead of re-scanning the
1621+
// descriptor, but only when the probed object IS the one getNode would
1622+
// scan (pb ?? v).
1623+
let accProbe: -1 | 0 | 1 = -1;
16051624
{
1606-
const acc =
1607-
node0 !== undefined
1608-
? (node0 as any).acc === true
1609-
: !inDraft(target) && getObserver() !== null && isOwnAccessor(src, key);
1625+
let acc: boolean;
1626+
if (node0 !== undefined) acc = (node0 as any).acc === true;
1627+
else if (!inDraft(target) && getObserver() !== null) {
1628+
acc = isOwnAccessor(src, key);
1629+
if (src === (target.pb ?? target.v)) accProbe = acc ? 1 : 0;
1630+
} else acc = false;
16101631
if (acc) {
16111632
if (!inDraft(target) && getObserver() !== null)
1612-
readNode(node0 ?? getNode(target, key, undefined));
1633+
readNode(node0 ?? getNode(target, key, undefined, accProbe));
16131634
const v = Reflect.get(src, key, receiver);
16141635
if (target.s) return serveShallow(target, key, v);
16151636
return isWrappable(v) ? draftServe(target, wrapNext(v, target, key)) : v;
@@ -1639,7 +1660,7 @@ const traps: ProxyHandler<StoreNextTarget> = {
16391660
// Reading a currently-absent own key subscribes to it (R12) — for any
16401661
// target OUTSIDE its own draft scope, even mid-setter (#3037, above).
16411662
if (v === undefined && !inDraft(target)) {
1642-
if (getObserver() !== null) readNode(getNode(target, key, undefined));
1663+
if (getObserver() !== null) readNode(getNode(target, key, undefined, accProbe));
16431664
const node = target.n?.[key];
16441665
if (node) {
16451666
const nv = nodeValue(node, undefined);
@@ -1668,7 +1689,7 @@ const traps: ProxyHandler<StoreNextTarget> = {
16681689
!(viewOvl && hasOwn.call(target.v, key))
16691690
)
16701691
return v; // proto method
1671-
return serveDataKey(target, key, v, src, node0);
1692+
return serveDataKey(target, key, v, src, node0, accProbe);
16721693
},
16731694

16741695
has(target, key) {

‎scripts/size/.size-limit.js‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ module.exports = [
115115
// Patch-channel removal (2026-09-02): 8.02 -> 7.98 KB, measured at
116116
// 7.95. The channel is deleted from next — regions own value delivery,
117117
// the unified-For design owns structure — reclaiming the store write-path emission seams retained by the core floor.
118-
limit: "7.98 KB",
118+
//
119+
// Store create-floor diet (2026-09-04): 7.98 -> 8.00 KB, measured at
120+
// 7.995. The slot-node unobserved dispatch sits on the two core sweep
121+
// sites (unlinkSubs, sweepTransientStoreNodes): a config-flag branch to
122+
// the ONE shared hook. slotSignal itself shakes out of storeless
123+
// bundles; these ~15 B buy the store scenarios their per-node closure/
124+
// NodeExtension diet (see the createStore note).
125+
limit: "8.00 KB",
119126
modifyEsbuildConfig
120127
},
121128
{
@@ -221,7 +228,18 @@ module.exports = [
221228
// Patch-channel removal (2026-09-02): 14.66 -> 14.05 KB, measured at
222229
// 14.00. The channel is deleted from next — regions own value delivery,
223230
// the unified-For design owns structure — reclaiming the write-path seams, wk struct indirection, and reconcile row-ops builders.
224-
limit: "14.05 KB",
231+
//
232+
// Store create-floor diet (2026-09-04): 14.05 -> 14.16 KB, measured at
233+
// 14.155. slotSignal (the pre-shaped store-leaf literal: _host/_key
234+
// backrefs replacing the per-node options object, equals closure,
235+
// unobserved closure, and NodeExtension) plus the get trap's first-read
236+
// dedupe (one descriptor probe threaded to node creation, one node-map
237+
// lookup, first-read wrap-cache population). ~105 B of retained code
238+
// that deletes four allocations + three hidden-class transitions per
239+
// store leaf: getNode self-time −23%, get-trap self-time −19%, dbmon
240+
// mount min −4%. Conscious speed-for-bytes trade, same ruling as the
241+
// Stage-3 hot-path batch.
242+
limit: "14.16 KB",
225243
modifyEsbuildConfig
226244
},
227245
{
@@ -452,7 +470,11 @@ module.exports = [
452470
// Patch-channel removal (2026-09-02): 26.99 -> 26.15 KB, measured at
453471
// 26.09. The channel is deleted from next — regions own value delivery,
454472
// the unified-For design owns structure — reclaiming the full store-family emission surface (value + row tiers).
455-
limit: "26.15 KB",
473+
//
474+
// Store create-floor diet (2026-09-04): 26.15 -> 26.25 KB, measured at
475+
// 26.248 — the slotSignal + first-read-dedupe bytes (see the
476+
// createStore note; this scenario retains all of it).
477+
limit: "26.25 KB",
456478
modifyEsbuildConfig
457479
},
458480
{

0 commit comments

Comments
 (0)