Modernize micro benchmarks: b.Loop and key=value case names - #2114
Merged
Conversation
radianceded
requested review from
bwplotka,
kakkoyun and
vesari
as code owners
September 9, 2026 13:07
bwplotka
approved these changes
Sep 10, 2026
bwplotka
left a comment
Member
There was a problem hiding this comment.
Please sign DCO, otherwise looks OK
- migrate sequential benchmarks from 'for i := 0; i < b.N; i++' to b.Loop, dropping the now-automatic timer management (ResetTimer / StopTimer around setup); - benchmarks that fan work out to goroutines sized by b.N (benchmarkHistogramObserve/Write, benchmarkSummaryObserve/Write, BenchmarkCounterWithLabelValuesConcurrent) and b.RunParallel (BenchmarkParallelCounter) keep their b.N form, which Loop does not cover; - vec_test's WithLabelValues permutation loop keeps its input rotation via an explicit counter, since Loop does not expose an index; - normalize b.Run case names to key=value so benchstat can project on them: series=/dp=/op=/type=/encoder= in the v1 API benchmarks, size= in the API client, op=/size= in promhttp, and labels=/constraint= in the counter vec table (following prometheus#2107). Fixes prometheus#2113 Signed-off-by: lr <2644847367@qq.com>
radianceded
force-pushed
the
modernize-microbenchmarks
branch
from
September 10, 2026 10:52
655030e to
35aa9ae
Compare
Contributor
Author
|
DCO signed in 35aa9ae — thanks for the review! |
bwplotka
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the sequential micro benchmarks to
b.Loopand normalizesb.Runcase names to the key=value format so benchstat can project on them (following #2107 and the linked benchmarks guide).b.Loopmigrations — benchmarks whose bodies are sequential: v1 API JSON serialization (all 12 leaf benchmarks), counter/gauge/summary/histogram vec+scalar benchmarks, GoCollector, Handler, SplitLines, promhttp compression handler, and the API client query benchmark. RedundantResetTimer/StopTimeraround setup are removed, sinceb.Loopmanages the timer and excludes setup automatically.Kept on
b.N— benchmarks that fan work out across goroutines sized byb.N(benchmarkHistogramObserve/Write,benchmarkSummaryObserve/Write,BenchmarkCounterWithLabelValuesConcurrent) andb.RunParallel(BenchmarkParallelCounter):b.Loopcovers single-goroutine iteration only.benchmarkMetricVecWithLabelValuesrotates its label-value input with an explicit counter sinceLoopexposes no index.Case renames:
series=N,dp=N,op=marshal|unmarshal,type=floats|histograms,encoder=json|jsonv2|jsonitersize=NKBop=<name>,size=<name>labels=<shape>,constraint=<yes|no>Verification:
go vet ./api/... ./prometheus/...clean; smoke runs of the migrated benchmarks (-benchtime=50x) and the fullgo test ./api/... ./prometheus/ ... ./prometheus/promhttp/...pass. The two runtime-metrics collector tests (TestGoCollector_ExposedMetrics,TestExpectedRuntimeMetrics) fail identically on an unmodified checkout with local Go 1.26 — a toolchain-version snapshot mismatch unrelated to this change.Fixes #2113