Skip to content

fix: collect setup garbage before timed bench samples - #152

Closed
natemoo-re wants to merge 1 commit into
mainfrom
natemoo-re/bench/gc-before-sample
Closed

natemoo-re wants to merge 1 commit into
mainfrom
natemoo-re/bench/gc-before-sample

Conversation

@natemoo-re

Copy link
Copy Markdown
Member

What does this PR do?

Every walltime sample runs setupUI() in beforeEach. That builds a new UI and tree, and the previous fixture becomes garbage. Nothing collects it before the timed function runs, so a GC pause for setup work can land inside a sample. The pause is charged to whichever tree shape and size happens to cross the threshold.

  • Each beforeEach now calls collectGarbage() (globalThis.gc?.()) after setup.
  • The bench project passes --expose-gc. Vite merges this with the flags the CodSpeed plugin adds. I checked that gc is a function inside the bench worker with the flag and undefined without it.

CodSpeed's memory instrument already runs with --expose-gc and calls gc() just before its single measured run, so this doesn't change memory results. Those peaks come from allocations inside the run (see #151). This is for walltime.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

No changeset: benchmark tooling only.

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026

Copy link
Copy Markdown

commit: 7ee0139

@codspeed

codspeed Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 240 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing natemoo-re/bench/gc-before-sample (7ee0139) with main (c35d878)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@natemoo-re

Copy link
Copy Markdown
Member Author

Closing: CodSpeed showed all 300 benchmarks unchanged (walltime included), while the forced gc() per sample pushed the CodSpeed job from ~11–15 min to 23.5 min. tinybench doesn't count hook time toward its per-bench budget, so every sample paid for a full GC. We can revisit this if walltime noise becomes a real problem.

@natemoo-re natemoo-re closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant