Skip to content

Commit a3f5c45

Browse files
authored
Add --force-gc support (#248)
Call globalThis.gc() before every benchmark to help debug cross-workload leaks.
1 parent 7f1aff9 commit a3f5c45

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

JetStreamDriver.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ const measureTotalTimeAsSubtest = false; // Once we move to preloading all resou
3030
const defaultIterationCount = 120;
3131
const defaultWorstCaseCount = 4;
3232

33-
if (!JetStreamParams.prefetchResources && isInBrowser)
33+
if (!JetStreamParams.prefetchResources && isInBrowser) {
3434
console.warn("Disabling resource prefetching! All compressed files must have been decompressed using `npm run decompress`");
35+
}
36+
37+
if (JetStreamParams.forceGC && typeof globalThis.gc === "undefined") {
38+
console.warn("Force-gc is set, but globalThis.gc() is not available.");
39+
}
3540

3641
if (!isInBrowser && JetStreamParams.prefetchResources) {
3742
// Use the wasm compiled zlib as a polyfill when decompression stream is
@@ -913,6 +918,14 @@ class Benchmark {
913918
if (this.isDone)
914919
throw new Error(`Cannot run Benchmark ${this.name} twice`);
915920
this._state = BenchmarkState.PREPARE;
921+
922+
if (JetStreamParams.forceGC) {
923+
// This will trigger for individual benchmarks in
924+
// GroupedBenchmarks since they delegate .run() to their inner
925+
// non-grouped benchmarks.
926+
globalThis?.gc();
927+
}
928+
916929
const scripts = isInBrowser ? new BrowserScripts(this.preloads) : new ShellScripts(this.preloads);
917930

918931
if (!!this.plan.deterministicRandom)

cli.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ const CLI_PARAMS = {
8181
help: "Custom code to run after each iteration.",
8282
param: "customPostIterationCode",
8383
},
84+
"force-gc": {
85+
help: "Force garbage collection before each benchmark, requires engine support.",
86+
param: "forceGC",
87+
},
8488
};
8589

8690
const cliParams = new Map();

utils/params.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Params {
4343
groupDetails = false
4444

4545
RAMification = false;
46+
forceGC = false;
4647
dumpJSONResults = false;
4748
dumpTestList = false;
4849
// Override iteration and worst-case counts per workload.
@@ -70,6 +71,7 @@ class Params {
7071
this.dumpJSONResults = this._parseBooleanParam(sourceParams, "dumpJSONResults");
7172
this.groupDetails = this._parseBooleanParam(sourceParams, "groupDetails");
7273
this.dumpTestList = this._parseBooleanParam(sourceParams, "dumpTestList");
74+
this.forceGC = this._parseBooleanParam(sourceParams, "forceGC");
7375

7476
this.customPreIterationCode = this._parseStringParam(sourceParams, "customPreIterationCode");
7577
this.customPostIterationCode = this._parseStringParam(sourceParams, "customPostIterationCode");

0 commit comments

Comments
 (0)