diff --git a/docs/introspection.md b/docs/introspection.md index 9e3fe464..f09cff91 100644 --- a/docs/introspection.md +++ b/docs/introspection.md @@ -13,3 +13,10 @@ ```bash CI=1 CODSPEED_DEBUG=true pnpm --filter with-typescript-esm bench-tinybench ``` + +## Garbage collection + +Memory and simulation modes receive `--expose-gc` through introspection. +The Benchmark.js plugin collects warmup garbage before starting instrumentation +for both synchronous and asynchronous benchmarks. This keeps the forced +collection outside the measured window. diff --git a/packages/benchmark.js-plugin/src/index.ts b/packages/benchmark.js-plugin/src/index.ts index fa69a35a..7d93d46d 100644 --- a/packages/benchmark.js-plugin/src/index.ts +++ b/packages/benchmark.js-plugin/src/index.ts @@ -207,6 +207,7 @@ async function runBenchmarks({ } else { optimizeFunctionSync(benchPayload); await mongoMeasurement.start(uri); + global.gc?.(); wrapWithRootFrameSync(() => { InstrumentHooks.startBenchmark(); benchPayload();