Skip to content

Commit 6bd8c91

Browse files
dinfuehrDominik Inführ
andauthored
feat: Use HeapSnapshotProxy.nodeIndexById (ChromeDevTools#2193)
Co-authored-by: Dominik Inführ <dinfuehr@chromium.org>
1 parent b646feb commit 6bd8c91

3 files changed

Lines changed: 9 additions & 31 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@types/yargs": "^17.0.33",
6464
"@typescript-eslint/eslint-plugin": "^8.43.0",
6565
"@typescript-eslint/parser": "^8.43.0",
66-
"chrome-devtools-frontend": "1.0.1641723",
66+
"chrome-devtools-frontend": "1.0.1642845",
6767
"core-js": "3.49.0",
6868
"debug": "4.4.3",
6969
"eslint": "^9.35.0",

src/HeapSnapshotManager.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import fsSync from 'node:fs';
88
import path from 'node:path';
99

10-
import {isNodeLike} from './formatters/HeapSnapshotFormatter.js';
1110
import {DevTools} from './third_party/index.js';
1211
import {
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

Comments
 (0)