Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/HeapSnapshotManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ export class HeapSnapshotManager {
{
snapshot: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotProxy;
worker: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy;
// TODO: use a multimap
idToClassKey: Map<number, string>;
// 1-indexed array where index is the class ID.
idToClassKey: string[];
classKeyToId: Map<string, number>;
idGenerator: () => number;
}
>();

Expand All @@ -65,9 +64,8 @@ export class HeapSnapshotManager {
this.#snapshots.set(absolutePath, {
snapshot,
worker,
idToClassKey: new Map<number, string>(),
idToClassKey: [''],
classKeyToId: new Map<string, number>(),
idGenerator: createIdGenerator(),
});

return snapshot;
Expand Down Expand Up @@ -114,9 +112,9 @@ export class HeapSnapshotManager {
const cached = this.#getCachedSnapshot(filePath);
let id = cached.classKeyToId.get(classKey);
if (!id) {
id = cached.idGenerator();
id = cached.idToClassKey.length;
cached.classKeyToId.set(classKey, id);
cached.idToClassKey.set(id, classKey);
cached.idToClassKey.push(classKey);
}
return id;
}
Expand Down Expand Up @@ -287,7 +285,7 @@ export class HeapSnapshotManager {
id: number,
): Promise<string | undefined> {
const cached = this.#getCachedSnapshot(filePath);
return cached.idToClassKey.get(id);
return cached.idToClassKey[id];
}

async #loadSnapshot(
Expand Down
Loading