77import fsSync from 'node:fs' ;
88import path from 'node:path' ;
99
10- import { isNodeLike } from './formatters/HeapSnapshotFormatter.js' ;
1110import { DevTools } from './third_party/index.js' ;
1211import {
1312 createIdGenerator ,
@@ -116,36 +115,15 @@ export class HeapSnapshotManager {
116115 return await provider . serializeItemsRange ( 0 , Infinity ) ;
117116 }
118117
119- async findNodeIndexById (
120- filePath : string ,
121- nodeId : number ,
122- ) : Promise < number | undefined > {
123- const snapshot = await this . getSnapshot ( filePath ) ;
124- const aggregates = await this . getAggregates ( filePath ) ;
125- const filter =
126- new DevTools . HeapSnapshotModel . HeapSnapshotModel . NodeFilter ( ) ;
127-
128- for ( const classKey of Object . keys ( aggregates ) ) {
129- const provider = snapshot . createNodesProviderForClass ( classKey , filter ) ;
130- const range = await provider . serializeItemsRange ( 0 , Infinity ) ;
131- for ( const item of range . items ) {
132- if ( isNodeLike ( item ) && item . id === nodeId ) {
133- return item . nodeIndex ;
134- }
135- }
136- }
137- return undefined ;
138- }
139-
140118 async getRetainers (
141119 filePath : string ,
142120 nodeId : number ,
143121 ) : Promise < DevTools . HeapSnapshotModel . HeapSnapshotModel . ItemsRange > {
144- const nodeIndex = await this . findNodeIndexById ( filePath , nodeId ) ;
122+ const snapshot = await this . getSnapshot ( filePath ) ;
123+ const nodeIndex = await snapshot . nodeIndexForId ( nodeId ) ;
145124 if ( nodeIndex === undefined ) {
146125 throw new Error ( `Node with ID ${ nodeId } not found` ) ;
147126 }
148- const snapshot = await this . getSnapshot ( filePath ) ;
149127 const provider = snapshot . createRetainingEdgesProvider ( nodeIndex ) ;
150128 return await provider . serializeItemsRange ( 0 , Infinity ) ;
151129 }
@@ -157,11 +135,11 @@ export class HeapSnapshotManager {
157135 maxNodes ?: number ,
158136 maxSiblings ?: number ,
159137 ) : Promise < DevTools . HeapSnapshotModel . HeapSnapshotModel . RetainingPaths > {
160- const nodeIndex = await this . findNodeIndexById ( filePath , nodeId ) ;
138+ const snapshot = await this . getSnapshot ( filePath ) ;
139+ const nodeIndex = await snapshot . nodeIndexForId ( nodeId ) ;
161140 if ( nodeIndex === undefined ) {
162141 throw new Error ( `Node with ID ${ nodeId } not found` ) ;
163142 }
164- const snapshot = await this . getSnapshot ( filePath ) ;
165143 return await snapshot . getRetainingPaths (
166144 nodeIndex ,
167145 maxDepth ,
0 commit comments