diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 80cd74ee..1d4c401d 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -30,8 +30,13 @@ const measureTotalTimeAsSubtest = false; // Once we move to preloading all resou const defaultIterationCount = 120; const defaultWorstCaseCount = 4; -if (!JetStreamParams.prefetchResources && isInBrowser) +if (!JetStreamParams.prefetchResources && isInBrowser) { console.warn("Disabling resource prefetching! All compressed files must have been decompressed using `npm run decompress`"); +} + +if (JetStreamParams.forceGC && typeof globalThis.gc === "undefined") { + console.warn("Force-gc is set, but globalThis.gc() is not available."); +} if (!isInBrowser && JetStreamParams.prefetchResources) { // Use the wasm compiled zlib as a polyfill when decompression stream is @@ -913,6 +918,14 @@ class Benchmark { if (this.isDone) throw new Error(`Cannot run Benchmark ${this.name} twice`); this._state = BenchmarkState.PREPARE; + + if (JetStreamParams.forceGC) { + // This will trigger for individual benchmarks in + // GroupedBenchmarks since they delegate .run() to their inner + // non-grouped benchmarks. + globalThis?.gc(); + } + const scripts = isInBrowser ? new BrowserScripts(this.preloads) : new ShellScripts(this.preloads); if (!!this.plan.deterministicRandom) diff --git a/cli.js b/cli.js index e1ff625f..c5a51dfa 100644 --- a/cli.js +++ b/cli.js @@ -81,6 +81,10 @@ const CLI_PARAMS = { help: "Custom code to run after each iteration.", param: "customPostIterationCode", }, + "force-gc": { + help: "Force garbage collection before each benchmark, requires engine support.", + param: "forceGC", + }, }; const cliParams = new Map(); diff --git a/utils/params.js b/utils/params.js index 11923ca0..92a632e9 100644 --- a/utils/params.js +++ b/utils/params.js @@ -43,6 +43,7 @@ class Params { groupDetails = false RAMification = false; + forceGC = false; dumpJSONResults = false; dumpTestList = false; // Override iteration and worst-case counts per workload. @@ -70,6 +71,7 @@ class Params { this.dumpJSONResults = this._parseBooleanParam(sourceParams, "dumpJSONResults"); this.groupDetails = this._parseBooleanParam(sourceParams, "groupDetails"); this.dumpTestList = this._parseBooleanParam(sourceParams, "dumpTestList"); + this.forceGC = this._parseBooleanParam(sourceParams, "forceGC"); this.customPreIterationCode = this._parseStringParam(sourceParams, "customPreIterationCode"); this.customPostIterationCode = this._parseStringParam(sourceParams, "customPostIterationCode");