diff --git a/package.json b/package.json index 52aa373..5233d0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chainsafe/benchmark", - "version": "1.1.0-rc.4", + "version": "1.1.0-rc.5", "repository": "git@github.com:chainsafe/benchmark.git", "author": "ChainSafe Systems", "license": "MIT", diff --git a/src/benchmark/reporter.ts b/src/benchmark/reporter.ts index 8b89ad5..36c5b0e 100644 --- a/src/benchmark/reporter.ts +++ b/src/benchmark/reporter.ts @@ -76,7 +76,7 @@ export class BenchmarkReporter { const ratio = result.averageNs / prevResult.averageNs; if (ratio > threshold) { - const fmt = this.indent() + color("fail", " " + symbols.err) + " " + resultRow; + const fmt = this.indent() + color("fail", " " + symbols.bang) + " " + resultRow; consoleLog(fmt); this.failed++; return; diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index ed4d4c2..7df341d 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -13,6 +13,7 @@ import {BenchmarkReporter} from "./reporter.js"; import {store} from "./globalState.js"; export class BenchmarkRunner implements VitestRunner { + readonly triggerGC: boolean; readonly config: VitestRunnerConfig; readonly reporter: BenchmarkReporter; readonly prevBench: Benchmark | null; @@ -29,6 +30,7 @@ export class BenchmarkRunner implements VitestRunner { setupFiles: benchmarkOpts.setupFiles ? benchmarkOpts.setupFiles.map((s) => path.resolve(s)) : [], retry: 0, }; + this.triggerGC = benchmarkOpts.triggerGC ?? false; this.prevBench = prevBench; this.benchmarkOpts = benchmarkOpts; this.reporter = new BenchmarkReporter({prevBench, benchmarkOpts}); @@ -50,6 +52,12 @@ export class BenchmarkRunner implements VitestRunner { onAfterRunTask(task: Task): void { this.reporter.onTestFinished(task); store.removeOptions(task); + + // To help maintain consistent memory usage patterns + // we trigger garbage collection manually + if (this.triggerGC && global.gc) { + global.gc(); + } } onAfterRunFiles(files: File[]): void { diff --git a/src/cli/options.ts b/src/cli/options.ts index 9aba20d..5fb06c8 100644 --- a/src/cli/options.ts +++ b/src/cli/options.ts @@ -191,4 +191,10 @@ export const benchmarkOptions: ICliCommandOptions = { default: [], group: benchmarkGroup, }, + triggerGC: { + type: "boolean", + description: "Trigger GC (if available) after every benchmark", + default: false, + group: benchmarkGroup, + }, }; diff --git a/src/types.ts b/src/types.ts index 672740e..b6fd508 100644 --- a/src/types.ts +++ b/src/types.ts @@ -63,6 +63,8 @@ export type BenchmarkOpts = { skip?: boolean; /** Setup files to load before the test files */ setupFiles?: string[]; + /** Trigger GC cleanup every test to have consistent memory usage */ + triggerGC?: boolean; }; // Create partial only for specific keys