@@ -41,7 +41,9 @@ import {
4141 readNodeFast ,
4242 setLatestReadActive ,
4343 setSignal ,
44+ setSlotUnobserved ,
4445 signal ,
46+ slotSignal ,
4547 untrack ,
4648 ext
4749} from "../../core/core.js" ;
@@ -222,50 +224,70 @@ export function unwrapValue(v: any): any {
222224// ---------------------------------------------------------------------------
223225// nodes: pure subscription points (values used only for equality gating)
224226
225- export function getNode ( target : StoreNextTarget , key : PropertyKey , current : any ) : Signal < any > {
227+ // Shared slot-node equality (create-floor diet): ONE function for every
228+ // store node — `this` is the node (method-call convention at every _equals
229+ // site), `_host` is the baked-in target backref. Logical-slot equality:
230+ // values resolving to the same child target are the same slot
231+ // (privatization/adoption swap raw identity without changing the logical
232+ // value — only changed leaves notify, R9).
233+ const slotNodeEquals = function ( this : any , a : any , b : any ) : boolean {
234+ return isEqual ( a , b ) || sameLogicalSlot ( this . _host , a , b ) ;
235+ } ;
236+
237+ // Shared slot-node unobserved handler (create-floor diet): registered once;
238+ // the core sweep dispatches CONFIG_SLOT_NODE nodes here instead of holding a
239+ // per-node closure in a per-node NodeExtension.
240+ setSlotUnobserved ( ( node : any ) : void => {
241+ // A live affects() mark keeps the node addressable (sweep parity).
242+ if ( node . _x ?. _affectsCount ) return ;
243+ const t : StoreNextTarget = node . _host ;
244+ const key : PropertyKey = node . _key ;
245+ if ( t . n && t . n [ key as any ] === node ) {
246+ delete t . n [ key as any ] ;
247+ t . nc -- ;
248+ }
249+ } ) ;
250+
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 > {
226261 const nodes = ( target . n ??= Object . create ( null ) ) ;
227262 let node : Signal < any > | undefined = nodes [ key ] ;
228263 if ( node === undefined ) {
229- const created : Signal < any > = ( node = signal (
264+ // Create-floor diet: slotSignal bakes the whole node into one literal —
265+ // no options object, no equals/unobserved closures, no NodeExtension,
266+ // no post-construction expandos (acc + the wrap cache px/pxv are
267+ // pre-shaped fields: the proxy last served for this key and the raw it
268+ // wrapped — one pointer compare replaces the per-read WeakMap lookup in
269+ // wrapNext). ownedWrite rides the literal's config: the setter carries
270+ // the owned-scope write guard; node-level setSignals are internal
271+ // notification machinery. Projection nodes carry the projection
272+ // computed as their firewall: reads through them link the derive's
273+ // status/lifecycle (§7b).
274+ const created : Signal < any > = ( node = slotSignal (
230275 current ,
231- {
232- // Attribution-only: name store property nodes by path segment so
233- // attribution chains and wide-scope warnings read "store.todos", not
234- // "signal". Gated on the engine being installed — node creation is
235- // the hottest store path, and the disabled cost must stay one null
236- // check (nodes created before enable() stay generically named).
237- name : __DEV__ && attrHooks !== null ? "store." + String ( key ) : undefined ,
238- // Logical-slot equality: values resolving to the same child target
239- // are the same slot (privatization/adoption swap raw identity without
240- // changing the logical value — only changed leaves notify, R9).
241- equals : ( a : any , b : any ) => isEqual ( a , b ) || sameLogicalSlot ( target , a , b ) ,
242- unobserved ( ) {
243- // A live affects() mark keeps the node addressable (sweep parity).
244- if ( ( created as any ) . _x ?. _affectsCount ) return ;
245- if ( target . n && target . n [ key ] === created ) {
246- delete target . n [ key ] ;
247- target . nc -- ;
248- }
249- }
250- } ,
251- // Projection nodes carry the projection computed as their firewall:
252- // reads through them link the derive's status/lifecycle (§7b).
276+ slotNodeEquals ,
277+ target ,
278+ key ,
279+ // Accessor-ness resolved ONCE per node (no per-object descriptor
280+ // scan on reads): accessor keys serve through Reflect.get with the
281+ // proxy receiver.
282+ accKnown === - 1 ? isOwnAccessor ( target . pb ?? target . v , key ) : accKnown === 1 ,
253283 ( target . fam ?. node as any ) ?? undefined
254284 ) ) ;
255- // Store nodes are ownedWrite: the setter carries the owned-scope write
256- // guard; node-level setSignals are internal notification machinery.
257- created . _config |= CONFIG_OWNED_WRITE ;
258- // Accessor-ness resolved ONCE per node (no per-object descriptor scan):
259- // accessor keys serve through Reflect.get with the proxy receiver.
260- ( created as any ) . acc = isOwnAccessor ( target . pb ?? target . v , key ) ;
261- // Wrap cache: the proxy last served for this key and the raw it wrapped.
262- // Raw-as-truth stores raw in nodes, so every object read needs a wrapper;
263- // one pointer compare (pxv === value) replaces the per-read WeakMap
264- // lookup in wrapNext — the dominant read-path cost vs legacy, whose
265- // nodes stored pre-wrapped values. A replaced child fails the compare
266- // and re-wraps; at most one stale proxy is pinned until the next read.
267- ( created as any ) . px = undefined ;
268- ( created as any ) . pxv = undefined ;
285+ // Attribution-only: name store property nodes by path segment so
286+ // attribution chains and wide-scope warnings read "store.todos", not
287+ // "signal". Gated on the engine being installed — node creation is
288+ // the hottest store path, and the disabled cost must stay one null
289+ // check (nodes created before enable() stay generically named).
290+ if ( __DEV__ && attrHooks !== null ) ( created as any ) . _name = "store." + String ( key ) ;
269291 // Optimistic families: arm the override slot — setSignal routes armed
270292 // nodes through the core engine (lanes, ownership, reverts all native).
271293 if ( target . fam ?. opt ) {
@@ -1379,7 +1401,8 @@ function serveDataKey(
13791401 key : PropertyKey ,
13801402 backingValue : any ,
13811403 src : Record < PropertyKey , any > ,
1382- node ?: Signal < any >
1404+ node ?: Signal < any > ,
1405+ accKnown : - 1 | 0 | 1 = - 1
13831406) : any {
13841407 const chained = target . ch && src === target . v ;
13851408 let v = backingValue ;
@@ -1428,7 +1451,9 @@ function serveDataKey(
14281451 v = nodeValue ( node , backingValue ) ;
14291452 }
14301453 } else if ( getObserver ( ) !== null ) {
1431- 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 ) ) ) ;
14321457 }
14331458 }
14341459 // Shallow stores serve data raw; store-proxy slots get boundary wrappers.
@@ -1533,8 +1558,11 @@ const traps: ProxyHandler<StoreNextTarget> = {
15331558 // tracked read of a present data key — the dbmon/uibench effect re-read
15341559 // shape. Skips serveDataKey's frame, the FORCE compare (only accessor
15351560 // 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 ] ;
15361564 if ( target . ch === false && writeScopes === null ) {
1537- const nodeH = target . n ?. [ key as any ] ;
1565+ const nodeH = node0 ;
15381566 if ( nodeH !== undefined && ( nodeH as any ) . acc !== true && getObserver ( ) !== null ) {
15391567 let nv = readNodeFast ( nodeH ) ;
15401568 if ( nv === READ_SLOW ) nv = readNode ( nodeH ) ;
@@ -1588,15 +1616,21 @@ const traps: ProxyHandler<StoreNextTarget> = {
15881616 // absent-key/accessor subscriptions for every store read during any
15891617 // derive, leaving nested projections permanently dependency-less when
15901618 // their sources hadn't materialized yet (#3037).
1591- 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 ;
15921624 {
1593- const acc =
1594- node0 !== undefined
1595- ? ( node0 as any ) . acc === true
1596- : ! 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 ;
15971631 if ( acc ) {
15981632 if ( ! inDraft ( target ) && getObserver ( ) !== null )
1599- readNode ( node0 ?? getNode ( target , key , undefined ) ) ;
1633+ readNode ( node0 ?? getNode ( target , key , undefined , accProbe ) ) ;
16001634 const v = Reflect . get ( src , key , receiver ) ;
16011635 if ( target . s ) return serveShallow ( target , key , v ) ;
16021636 return isWrappable ( v ) ? draftServe ( target , wrapNext ( v , target , key ) ) : v ;
@@ -1626,7 +1660,7 @@ const traps: ProxyHandler<StoreNextTarget> = {
16261660 // Reading a currently-absent own key subscribes to it (R12) — for any
16271661 // target OUTSIDE its own draft scope, even mid-setter (#3037, above).
16281662 if ( v === undefined && ! inDraft ( target ) ) {
1629- if ( getObserver ( ) !== null ) readNode ( getNode ( target , key , undefined ) ) ;
1663+ if ( getObserver ( ) !== null ) readNode ( getNode ( target , key , undefined , accProbe ) ) ;
16301664 const node = target . n ?. [ key ] ;
16311665 if ( node ) {
16321666 const nv = nodeValue ( node , undefined ) ;
@@ -1655,7 +1689,7 @@ const traps: ProxyHandler<StoreNextTarget> = {
16551689 ! ( viewOvl && hasOwn . call ( target . v , key ) )
16561690 )
16571691 return v ; // proto method
1658- return serveDataKey ( target , key , v , src , node0 ) ;
1692+ return serveDataKey ( target , key , v , src , node0 , accProbe ) ;
16591693 } ,
16601694
16611695 has ( target , key ) {
0 commit comments