docs/plans/benchmark-improvements/001-migrate-benchmarkjs-to-tinybench.md
Migrate all benchmark files from benchmark.js (legacy, unmaintained) to tinybench (modern, maintained). This involves updating the benchmarking library, plugin, and refactoring all benchmark files to use the tinybench API.
benchmark.js is unmaintained (last release 2016)tinybench is actively maintained with modern ESM support@codspeed/tinybench-plugin (v5.0.1) which is already at version parity with the benchmark.js plugindeferred patternpackage.json - No direct codspeed dependency here, only uses scriptspackages/client/package.json - Replace @codspeed/benchmark.js-plugin and benchmark with tinybench equivalentspackages/client-engine-runtime/package.json - Replace dependenciespackages/get-platform/package.json - Replace dependenciespackages/client/src/__tests__/benchmarks/query-performance/query-performance.bench.tspackages/client/src/__tests__/benchmarks/query-performance/compilation.bench.tspackages/client/src/__tests__/benchmarks/huge-schema/huge-schema.bench.tspackages/client/src/__tests__/benchmarks/lots-of-relations/lots-of-relations.bench.tspackages/client-engine-runtime/bench/interpreter.bench.tspackages/get-platform/bench/get-platform.bench.tsFor each package with benchmarks, replace:
// Before
"@codspeed/benchmark.js-plugin": "4.0.0",
"@types/benchmark": "2.1.5",
"benchmark": "2.1.4",
// After
"@codspeed/tinybench-plugin": "5.0.1",
"tinybench": "^4.0.1",
Imports:
// Before
import { withCodSpeed } from '@codspeed/benchmark.js-plugin'
import Benchmark from 'benchmark'
// After
import { withCodSpeed } from '@codspeed/tinybench-plugin'
import { Bench } from 'tinybench'
Suite Creation:
// Before
const suite = withCodSpeed(new Benchmark.Suite('suite-name'))
// After
const bench = withCodSpeed(new Bench({ name: 'suite-name' }))
Adding Sync Benchmarks:
// Before
suite.add('benchmark name', {
fn: function () {
doSomething()
},
})
// After
bench.add('benchmark name', () => {
doSomething()
})
Adding Async Benchmarks (major simplification):
// Before (deferred pattern)
suite.add('benchmark name', {
defer: true,
fn: function (deferred: Benchmark.Deferred) {
doSomethingAsync()
.then(() => deferred.resolve())
.catch((err) => {
console.error(err)
process.exit(1)
})
},
})
// After (native async/await)
bench.add('benchmark name', async () => {
await doSomethingAsync()
})
Running and Output:
// Before
suite
.on('cycle', (event: Benchmark.Event) => {
console.log(String(event.target))
})
.on('complete', () => {
console.log('Benchmarks complete.')
})
.run({ async: true })
// After
await bench.run()
console.table(bench.table())
Update docs/benchmarking.md to reflect tinybench API:
# Run all benchmarks locally
pnpm bench
# Run specific benchmark
pnpm bench query-performance
# Verify CodSpeed integration
CODSPEED_BENCHMARK=true pnpm bench
benchmark or @codspeed/benchmark.js-plugin in package.json filespnpm bench runs successfullypnpm bench-stdout-only runs successfullyrhysd/github-action-benchmark@v1 action in CI still works with tinybench output format{ throws: true } to Bench options for better error visibility