@@ -126,8 +126,7 @@ export type NodeProperty = string | number | boolean | object | null
126126/** Captures only the {@link layoutStore} singleton, so shared across nodes. */
127127const layoutMutations = useLayoutMutations ( )
128128
129- /** Scratch for store rect reads that must not allocate. */
130- const storedRect = new Float64Array ( 4 )
129+ const storedRectScratch = new Float64Array ( 4 )
131130
132131interface INodePropertyInfo {
133132 name ?: string
@@ -622,19 +621,6 @@ export class LGraphNode
622621 return [ posX - bX , posY - bY ]
623622 }
624623
625- /**
626- * A frame-scoped projection of the node's geometry, which `layoutStore` owns.
627- *
628- * Reading straight from the store on every access costs ~57ns against a
629- * realistic document, and the legacy canvas reads a node's geometry dozens of
630- * times per frame. The rect is refreshed once per dirty signal and read
631- * locally after that - ADR 0008's first render-loop mitigation, pre-collecting
632- * a query rather than probing the store per draw call.
633- *
634- * It is a projection, never a source: nothing reads it back into the store,
635- * and it cannot go stale because every store write bumps the version that
636- * invalidates it.
637- */
638624 _posSize = new Rectangle ( )
639625 _pos : Point = this . _posSize . pos
640626 _size : Size = this . _posSize . size
@@ -647,17 +633,10 @@ export class LGraphNode
647633 synchronize : ( ) => this . refreshGeometry ( )
648634 } )
649635
650- /** The `layoutStore.geometryVersion` this projection was built from. */
651636 _geometryVersion = - 1
652637
653- /**
654- * Whether the store holds this node's geometry. Until it does — before the
655- * node is attached — {@link _posSize} is the geometry, not a projection of
656- * it, and must not be overwritten by whatever entry happens to share the id.
657- */
658638 _layoutRegistered = false
659639
660- /** Rebuilds {@link _posSize} if the store has changed since it was read. */
661640 private refreshGeometry ( ) : void {
662641 if ( ! this . _layoutRegistered ) return
663642
@@ -686,9 +665,9 @@ export class LGraphNode
686665
687666 const position = { x : this . _pos [ 0 ] , y : this . _pos [ 1 ] }
688667 if (
689- layoutStore . readNodeRect ( this . id , storedRect ) &&
690- storedRect [ 0 ] === position . x &&
691- storedRect [ 1 ] === position . y
668+ layoutStore . readNodeRect ( this . id , storedRectScratch ) &&
669+ storedRectScratch [ 0 ] === position . x &&
670+ storedRectScratch [ 1 ] === position . y
692671 ) {
693672 return
694673 }
@@ -721,12 +700,10 @@ export class LGraphNode
721700 private _sizeUpdated ( ) : void {
722701 if ( this . id === UNASSIGNED_NODE_ID || ! this . graph ) return
723702
724- // An equal write would bump the store version, which invalidates every
725- // node's geometry projection, so it is worth a read to avoid.
726703 if (
727- layoutStore . readNodeRect ( this . id , storedRect ) &&
728- storedRect [ 2 ] === this . _size [ 0 ] &&
729- storedRect [ 3 ] === this . _size [ 1 ]
704+ layoutStore . readNodeRect ( this . id , storedRectScratch ) &&
705+ storedRectScratch [ 2 ] === this . _size [ 0 ] &&
706+ storedRectScratch [ 3 ] === this . _size [ 1 ]
730707 ) {
731708 return
732709 }
@@ -4413,36 +4390,6 @@ export function registerNodeState(
44134390 * node. No-op for nodes that were never registered.
44144391 * @param node The node to unregister
44154392 */
4416- /**
4417- * Hands the node's geometry to {@link layoutStore} and switches it to reading
4418- * from there. Called from `LGraph.add`, after the node has an id.
4419- * @param node The node to register
4420- */
4421- export function registerNodeLayout ( node : LGraphNode , zIndex : number ) : void {
4422- layoutMutations . setSource ( LayoutSource . Canvas )
4423- layoutMutations . createNode ( node . id , {
4424- position : { x : node . _pos [ 0 ] , y : node . _pos [ 1 ] } ,
4425- size : { width : node . _size [ 0 ] , height : node . _size [ 1 ] } ,
4426- zIndex,
4427- visible : true
4428- } )
4429- node . _layoutRegistered = true
4430- node . _geometryVersion = layoutStore . geometryVersion
4431- }
4432-
4433- /**
4434- * Drops the node's layout entry. The node keeps its last known geometry
4435- * locally, so a detached node still reports where it was.
4436- * @param node The node to unregister
4437- */
4438- export function unregisterNodeLayout ( node : LGraphNode ) : void {
4439- if ( ! node . _layoutRegistered ) return
4440-
4441- node . _layoutRegistered = false
4442- layoutMutations . setSource ( LayoutSource . Canvas )
4443- layoutMutations . deleteNode ( node . id )
4444- }
4445-
44464393export function unregisterNodeState ( node : LGraphNode ) : void {
44474394 if ( ! node . _graphId ) return
44484395 useNodeDataStore ( ) . deleteNode ( node . _graphId , node . _state )
0 commit comments