Skip to content

Benchmarks

Benchmarks are for performance-sensitive code paths where regressions are easy to miss in correctness tests: repoindex search, CAS storage, DB scan helpers, execution setup, domain builders, and shared time utilities.

Terminal window
bun run bench:go

The runner writes a timestamped copy of the output under /private/tmp/foxctl-benchmarks/ and prints the path at the end.

Use environment variables to keep local experiments repeatable:

VariableDefaultPurpose
BENCH_COUNT3Number of benchmark samples per package
BENCH_TIME1sPer-benchmark timing target passed to go test
BENCH_PATTERN.Regex for matching benchmark names
BENCH_OUTtimestamped file in /private/tmpOutput capture path

Example focused run:

Terminal window
BENCH_COUNT=5 BENCH_TIME=2s BENCH_PATTERN=Repoindex bun run bench:go ./internal/intelligence/indexing/repoindex

The default suite covers packages that already contain benchmarks:

PackageWhy it is included
./internal/domain/agentAgent profile and builder allocation behavior
./internal/intelligence/indexing/repoindexSearch, scoring, fallback, and query paths
./internal/platform/timeutilShared time formatting and parsing helpers
./internal/runtime/execution/execCommand execution setup and hot-path overhead
./internal/storage/casContent-addressed storage write/read behavior
./internal/storage/dbutilScan helper overhead for storage rows

Add a package to scripts/run-go-benchmarks.sh only when the benchmark protects a known hot path or a previously regressed operation. Keep benchmark inputs deterministic, avoid network access, and prefer explicit fixtures over host machine state.

The benchmark suite is organized around concrete performance risks:

SolutionProtected behaviorSignal to watch
Curated runnerKeeps benchmark invocation repeatable across local agents and CI-style checksCommand exits cleanly and captures output path
Repoindex search benchmarksProtects zero-result fallback, scored search, syntax fallback, and query allocation behaviorns/op, B/op, and allocs/op drift
CAS buffer benchmarksProtects write/read buffering and large artifact handlingThroughput and allocation drift
Slice preallocation benchmarksGuards against accidental allocation regressions in hot storage loopsAllocation count changing from zero
Context cancellation benchmarksMakes cancellation checks visible in storage loopsUnexpected overhead or behavior drift
DB scan helper benchmarksProtects timestamp and JSON row scan helper costB/op and allocs/op drift
Time utility benchmarksKeeps common time format/parse helpers honestAllocation-free parsing stays allocation-free

When a benchmark fails or drifts, fix the underlying hot path first. Update the benchmark only when the new behavior is intentional and the docs explain the new expected cost.