Repository navigation
test: add benchmarks, runnable examples, and bench-regression infrastructure #15
Copy link
Copy link
Closed
Labels
P1Important, not blockingImportant, not blockingperformancePerformance-related changePerformance-related changetestingTests: unit, BDD, benchmarks, fuzzTests: unit, BDD, benchmarks, fuzz
Description
test: add benchmarks, runnable examples, and bench-regression infrastructure
Summary
Add syncmap_bench_test.go (benchmarks for every public method plus concurrent patterns and an overhead comparison against raw sync.Map), example_test.go (runnable godoc Example functions for every public symbol), and the bench.txt baseline + scripts/check-bench-regression.sh wiring that re-enables mask's benchstat-regression-guard CI job.
Requirements
syncmap_bench_test.go(package syncmap_test, Apache 2.0 header):- One
Benchmark*per public symbol:BenchmarkLoad,BenchmarkStore,BenchmarkLoadOrStore,BenchmarkLoadAndDelete,BenchmarkDelete,BenchmarkRange,BenchmarkLen,BenchmarkMap,BenchmarkKeys,BenchmarkValues(orItemsif rename #(rename-issue) hasn't landed),BenchmarkSwap,BenchmarkClear,BenchmarkCompareAndSwap,BenchmarkCompareAndDelete. - Every benchmark calls
b.ReportAllocs(). - Concurrent patterns:
BenchmarkConcurrentReadWritewithb.RunParalleland a realistic read/write ratio. - Overhead comparison:
BenchmarkOverhead_LoadSyncMapvsBenchmarkOverhead_LoadRawSyncMap(and the same pair for Store, Delete, LoadOrStore, LoadAndDelete) to quantify the generic-wrapper cost.
- One
example_test.go(package syncmap_test, Apache 2.0 header):- One
Example*per public symbol —ExampleSyncMap,ExampleSyncMap_Load,ExampleSyncMap_Store, etc. — each ending with// Output:so they run undergo test.
- One
bench.txt— committed baseline, produced bygo test -bench=. -benchmem -run=^$ -count=5 ./... > bench.txton an ubuntu-latest-equivalent host.scripts/check-bench-regression.sh— mirror mask's script verbatim (adjust repo-specific paths if any). Exits non-zero when benchstat reports a regression beyond the tolerated threshold.- Makefile — re-add the
bench-regressiontarget (removed in chore: align CI, release, and tooling to axonops/mask pattern #8 for lack of script).makefile-targets-guardinci.ymlupdates its expected list to include it. ci.yml— re-enable thebenchstat-regression-guardjob from mask (currently commented out / deferred).- Apache headers on all new
.gofiles. No AI-attribution tokens. No timing-based synchronisation in Examples (useWaitGroupif any goroutine is spawned; ideally Examples are single-threaded). - Benchmarks must have zero additional allocations beyond what
sync.Mapitself allocates forLoad,Store,Delete,LoadOrStore,LoadAndDelete— confirmed byb.ReportAllocs()output and compared to the raw-sync.Mapbaseline.
Acceptance Criteria
syncmap_bench_test.goexists with ≥14Benchmark*functions (one per public symbol plus concurrent + overhead sets).example_test.goexists with ≥10Example*functions, one per public symbol.go test -run 'Example' ./...passes — all Examples have matching// Output:blocks.go test -bench=. -benchmem -run=^$ -count=1 ./...produces output for every benchmark;allocs/opforBenchmarkLoad,BenchmarkStore,BenchmarkDelete,BenchmarkLoadOrStore,BenchmarkLoadAndDeletematches (or is within one alloc of) the correspondingBenchmarkOverhead_…RawSyncMapbaseline.bench.txtexists at repo root and containscount=5sample runs for everyBenchmark*.scripts/check-bench-regression.shexists, is executable, and mirrors mask's script.make bench-regressionruns benchstat againstbench.txtvs a freshcurrent.txtand exits 0 on an unchanged tree.makefile-targets-guardpasses withbench-regressionadded to its expected list.benchstat-regression-guardjob inci.ymlis enabled and passes on this PR.make checkand CI green.
Testing Requirements
go test -run 'Example' ./...— green.make bench-regression— green locally on an unchanged tree.- CI
benchstat-regression-guard— green on this PR. - Coverage not regressed (Examples may add to coverage; benchmarks don't affect
-cover).
Documentation Requirements
- Each Example's comment above the function briefly describes the scenario (matching godoc example conventions).
- README additions for "Performance" section (one-line summary + link to the benchstat report) live in feat: add top-level CompareAndSwap and CompareAndDelete functions #14.
Dependencies
- Blocked by: test: rewrite unit tests to external package with testify/goleak; coverage ≥95% #10 (test scaffolding), plus ideally chore: align CI, release, and tooling to axonops/mask pattern (#8) #9 (Swap, Clear) and test: rewrite unit tests to external package with testify/goleak; coverage ≥95% #10 CAS (CompareAndSwap/Delete) so their benchmarks can land in this PR rather than a follow-up. If those haven't merged, this PR benchmarks what exists and a minor follow-up adds the missing benchmarks.
- Blocks: v1.0.0 release quality gate — performance regression protection.
Labels
testingperformanceP1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Important, not blockingImportant, not blockingperformancePerformance-related changePerformance-related changetestingTests: unit, BDD, benchmarks, fuzzTests: unit, BDD, benchmarks, fuzz
Activity
millerjp commentedon Apr 20, 2026
Bookkeeping from #14 (merged via PR #22):
syncmap_bench_test.gonow exists on main and already containsBenchmarkCompareAndSwap,BenchmarkCompareAndSwapMismatch,BenchmarkCompareAndDelete,BenchmarkCompareAndSwapParallel. #15 extends this file with benchmarks for every other public method, the raw-sync.Map overhead comparison set, and the committedbench.txtbaseline +scripts/check-bench-regression.sh.test: add benchmarks, examples, and bench-regression guard (#15)