Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/introspection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ async function runBenchmarks({
} else {
optimizeFunctionSync(benchPayload);
await mongoMeasurement.start(uri);
global.gc?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 GC ordering has no test

The new collection has no regression test. Existing tests check that startBenchmark runs, but not whether global.gc runs before it. Removing this fix or moving collection into the measured window would still pass those tests.

Add a temporary global.gc mock and check that collection runs after warmup and before startBenchmark. Also cover missing GC and fallback execution, and restore the original global afterward.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/benchmark.js-plugin/src/index.ts
Line: 210

Comment:
**GC ordering has no test**

The new collection has no regression test. Existing tests check that `startBenchmark` runs, but not whether `global.gc` runs before it. Removing this fix or moving collection into the measured window would still pass those tests.

Add a temporary `global.gc` mock and check that collection runs after warmup and before `startBenchmark`. Also cover missing GC and fallback execution, and restore the original global afterward.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

wrapWithRootFrameSync(() => {
InstrumentHooks.startBenchmark();
benchPayload();
Expand Down
Loading