Skip to content

chore(deps): upgrade tinybench to v6#7100

Closed
jerome-benoit wants to merge 44 commits intovitest-dev:mainfrom
jerome-benoit:chore/tinybench-upgrade
Closed

chore(deps): upgrade tinybench to v6#7100
jerome-benoit wants to merge 44 commits intovitest-dev:mainfrom
jerome-benoit:chore/tinybench-upgrade

Conversation

@jerome-benoit
Copy link
Copy Markdown

@jerome-benoit jerome-benoit commented Dec 18, 2024

Description

Upgrade tinybench from v2.9.0 to v6.0.0.

Breaking changes adapted:

  • TaskResult is now a discriminated union — BenchmarkResult redefined as standalone vitest-owned interface with BenchmarkStatistics type and createEmptyStatistics() helper for type-safe defaults
  • Deprecated top-level fields removed (hz, samples, mean, etc.) — using latency.*, throughput.* instead
  • retainSamples option (defaults to false) replaces manual samples.length = 0 clearing — mapped to vitest's includeSamples via centralized getBenchOptions
  • BenchEvent is now a typed class — event handlers use typed event API
  • BenchmarkResult.sampleCount renamed to samplesCount to align with Statistics.samplesCount

Bug fixes included:

  • Fix complete event handler crash when task errors — tinybench v6 fires complete after error, but errored tasks have no latency property. Added task state guard and error tracking
  • Fix errored benchmarks silently marked as pass — now correctly marked as fail
  • Replace Object.assign(result, task.result) with selective field extraction — prevents tinybench runtime metadata (runtime, runtimeVersion, timestampProviderName) from polluting BenchmarkResult and JSON output
  • Fix comparison display diffFixed check ('1.0.0''1.00') with proper else if chain

User-facing type change: BenchmarkResult.sampleCountBenchmarkResult.samplesCount. BenchTaskResult re-export is now the tinybench v6 TaskResult discriminated union.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
@jerome-benoit jerome-benoit marked this pull request as draft December 18, 2024 12:01
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 18, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8030df8
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d89cb611489200082672c1
😎 Deploy Preview https://deploy-preview-7100--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gperdomor
Copy link
Copy Markdown

@jerome-benoit any progress with this?... Can you migrate this to v4? 🙏🏻

@jerome-benoit
Copy link
Copy Markdown
Author

It's still on my TODO list, but I had no time to finish the migration.

@gperdomor
Copy link
Copy Markdown

@jerome-benoit thank you for the quick response... I hope you find some time to finish 👍🏻

…rade

# Conflicts:
#	packages/vitest/src/runtime/runners/benchmark.ts
#	test/benchmark/test/reporter.test.ts
…stream merge

- Use latency.mean instead of deprecated mean in benchmark ranking sort
- Guard filter with benchmark?.latency to handle in-progress benchmarks
- Simplify error handler with null-safe access (e.task?.result?.error)
- Remove dead test:benchmark script referencing deleted workspace
@jerome-benoit jerome-benoit changed the title chore(deps): update tinybench to 3.x.x chore(deps): upgrade tinybench to v6 Mar 4, 2026
@jerome-benoit jerome-benoit marked this pull request as ready for review March 4, 2026 19:38
Copilot AI review requested due to automatic review settings March 4, 2026 19:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Upgrades Vitest’s benchmarking integration to work with tinybench@6, adapting internal result types and benchmark reporting/runner logic to match tinybench’s new discriminated-union results and latency/throughput statistics model.

Changes:

  • Bump tinybench dependency to ^6.0.0 (lockfile + package dependency).
  • Refactor runtime benchmark runner/types to use tinybench v6 task/results and map includeSamples to retainSamples.
  • Update benchmark reporters/tests to read from latency.* / throughput.* instead of deprecated top-level stats.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/cli/test/benchmarking.test.ts Updates include-samples assertions to match v6 latency.samples behavior.
pnpm-lock.yaml Locks tinybench@6.0.0 and updates related dependency metadata.
packages/vitest/src/runtime/types/benchmark.ts Redefines benchmark result/statistics types for v6 (latency/throughput, samples handling).
packages/vitest/src/runtime/runners/benchmark.ts Refactors benchmark execution to Bench.run() and v6 events/results.
packages/vitest/src/runtime/benchmark.ts Tightens benchmark options storage/types and adds formatted name into options.
packages/vitest/src/public/index.ts Updates public type re-exports to new tinybench v6 aliases.
packages/vitest/src/node/reporters/benchmark/tableRender.ts Updates table rendering to use latency.* and compare via throughput.mean.
packages/vitest/src/node/reporters/benchmark/reporter.ts Updates sorting/ranking logic to use latency.mean.
packages/vitest/src/node/reporters/benchmark/json-formatter.ts Stops forcibly overriding samples in JSON output.
packages/vitest/src/node/reporters/base.ts Updates benchmark summary ratio calculation to use latency.mean.
packages/vitest/package.json Bumps tinybench dependency to ^6.0.0.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

You can also share your feedback on Copilot code review. Take the survey.

jerome-benoit and others added 7 commits March 4, 2026 21:08
Guard complete handler against errored/aborted tasks to prevent TypeError crash. Track error state to correctly mark failed benchmarks. Replace Object.assign with selective field extraction to prevent tinybench runtime metadata from leaking into BenchmarkResult and JSON output.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Move retainSamples (includeSamples → retainSamples) mapping from the runner call site into getBenchOptions, which now takes the runner config and returns ready-to-use tinybench BenchOptions.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Rename numberOfSamples to samplesCount to match tinybench Statistics.samplesCount.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@jerome-benoit
Copy link
Copy Markdown
Author

Hey @sheremet-va @hi-ogawa @AriPerkkio 👋

This PR is finally ready for review! It's been sitting around since December 2024, but it's now fully up to date with main and covers the complete tinybench v2.9.0 → v6.0.0 upgrade.

Beyond the API migration, this includes a few correctness fixes found during an audit of the benchmarking code path (error handling in the complete event, Object.assign result pollution, diffFixed comparison bug). All details in the PR description.

CI is green (the browser test flake on the previous run was from the upstream merge and has since been fixed). Happy to address any feedback. Thanks!

@sheremet-va
Copy link
Copy Markdown
Member

Hey! Thank you for the PR and sorry for the lack of communication, but we currently don't want to accept PRs targeting benchmarking features because we have a big rewrite on our road map that changes the whole architecture to not treat bench functions as tests: #7850

By accepting this PR we might introduce bugs that need to be fixed in an already kind of softly deprecated feature, so I would rather avoid any turbulence at this time.

@sheremet-va
Copy link
Copy Markdown
Member

sheremet-va commented Apr 10, 2026

Hey! Sorry for keeping you waiting. I incorporated some of your changes in #10113 (docs). Would love to know your opinion on the proposed design.

@jerome-benoit
Copy link
Copy Markdown
Author

Hey! Sorry for keeping you waiting. I incorporated some of your changes in #10113 (docs). Would love to know your opinion on the proposed design.

An PR sync automation was updating that PR. I guess I can close it. I will look at the other when time permits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants