Skip to content

Commit d052de8

Browse files
chore(bench): rename LargeRoot memory benchmark to .mem.ts; remove try/catch/logging; restore generator inline comment; remove bench/all.ts CI filter
Co-Authored-By: Harry Brundage <[email protected]>
1 parent 293737a commit d052de8

File tree

5 files changed

+59
-77
lines changed

5 files changed

+59
-77
lines changed

Benchmarking.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ Run it with:
8383

8484
```sh
8585
# default N=10 instances
86-
pnpm x bench/memory-large-root.benchmark.ts
86+
pnpm x bench/memory-large-root.mem.ts
8787

8888
# with GC exposed for cleaner readings
89-
node --expose-gc -r ts-node/register/transpile-only bench/memory-large-root.benchmark.ts
89+
node --expose-gc -r ts-node/register/transpile-only bench/memory-large-root.mem.ts
9090

9191
# control number of instances retained
92-
MQT_MEMORY_N=20 pnpm x bench/memory-large-root.benchmark.ts
92+
MQT_MEMORY_N=20 pnpm x bench/memory-large-root.mem.ts
9393
```
9494

9595
Notes:

bench/all.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export const runAll = async () => {
1616

1717
let benchmarkFiles = await globby(__dirname + "/**/*.benchmark.ts");
1818

19-
if (process.env.CI) {
20-
benchmarkFiles = benchmarkFiles.filter((file) => !file.includes("memory-large-root.benchmark.ts"));
21-
}
2219

2320
let suite = createSuite();
2421

bench/memory-large-root.benchmark.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

bench/memory-large-root.mem.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import findRoot from "find-root";
2+
import fs from "fs";
3+
import { LargeRoot } from "../spec/fixtures/LargeRoot";
4+
import { benchmarker, newInspectorSession } from "./benchmark";
5+
6+
const snapshot = JSON.parse(fs.readFileSync(findRoot(__dirname) + "/spec/fixtures/large-root-snapshot.json", "utf8"));
7+
8+
const roots: any[] = [];
9+
const key = Date.now();
10+
let wrote = false;
11+
12+
export default benchmarker(
13+
async (suite) => {
14+
const N = Number(process.env.MQT_MEMORY_N || 10);
15+
16+
suite.add(`instantiate and retain LargeRoot (N=${N})`, function () {
17+
if ((globalThis as any).gc) (globalThis as any).gc();
18+
const before = process.memoryUsage().heapUsed;
19+
20+
for (let i = 0; i < N; i++) {
21+
roots.push(LargeRoot.createReadOnly(snapshot));
22+
}
23+
24+
if ((globalThis as any).gc) (globalThis as any).gc();
25+
const after = process.memoryUsage().heapUsed;
26+
27+
if (!wrote) {
28+
wrote = true;
29+
30+
const jsonPath = `./bench-LargeRoot-${key}.json`;
31+
fs.writeFileSync(jsonPath, JSON.stringify({ N, before, after, delta: after - before }, null, 2), "utf8");
32+
console.log(`Wrote ${jsonPath}`);
33+
34+
if (!(process.env.CI || process.env.CODSPEED || process.env.MQT_MEMORY_HEAPSNAP === "0")) {
35+
const { session, post } = newInspectorSession();
36+
const chunks: string[] = [];
37+
session.on("HeapProfiler.addHeapSnapshotChunk", (m: any) => chunks.push(m.params.chunk));
38+
post("HeapProfiler.enable")
39+
.then(() => post("HeapProfiler.takeHeapSnapshot", { reportProgress: false }))
40+
.then(() => {
41+
const hsPath = `./bench-LargeRoot-${key}.heapsnapshot`;
42+
fs.writeFileSync(hsPath, chunks.join(""), "utf8");
43+
console.log(`Wrote ${hsPath}`);
44+
})
45+
.finally(() => {
46+
void post("HeapProfiler.disable");
47+
});
48+
}
49+
}
50+
});
51+
52+
return suite;
53+
},
54+
{ iterations: 1, warmupIterations: 0, warmupTime: 0, time: 0 }
55+
);

src/fast-instantiator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
113113
}
114114
}
115115
116-
context.referencesToResolve = null;
116+
context.referencesToResolve = null; // cleanup the list of references to resolve, no need to retain them past construction
117117
118118
return instance;
119119
};

0 commit comments

Comments
 (0)