refactor: Use array instead of Map for idToClassKey (#2321)

Switches idToClassKey to an array since ids are strictly incremented
from 1. This also allows us to drop the id generator use.

Co-authored-by: Dominik Inführ <dinfuehr@chromium.org>
This commit is contained in:
Dominik Inführ
2026-07-08 17:22:44 +02:00
committed by GitHub
parent a8c7c73ca5
commit ff53b7bb82
+6 -8
View File
@@ -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;
}
>();
@@ -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;
@@ -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;
}
@@ -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(