Skip to content

Modernize micro benchmarks: b.Loop and key=value case names - #2114

Merged
bwplotka merged 1 commit into
prometheus:mainfrom
radianceded:modernize-microbenchmarks
Sep 10, 2026
Merged

Modernize micro benchmarks: b.Loop and key=value case names#2114
bwplotka merged 1 commit into
prometheus:mainfrom
radianceded:modernize-microbenchmarks

Conversation

@radianceded

Copy link
Copy Markdown
Contributor

Migrates the sequential micro benchmarks to b.Loop and normalizes b.Run case names to the key=value format so benchstat can project on them (following #2107 and the linked benchmarks guide).

b.Loop migrations — 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. Redundant ResetTimer/StopTimer around setup are removed, since b.Loop manages the timer and excludes setup automatically.

Kept on b.N — benchmarks that fan work out across goroutines sized by b.N (benchmarkHistogramObserve/Write, benchmarkSummaryObserve/Write, BenchmarkCounterWithLabelValuesConcurrent) and b.RunParallel (BenchmarkParallelCounter): b.Loop covers single-goroutine iteration only. benchmarkMetricVecWithLabelValues rotates its label-value input with an explicit counter since Loop exposes no index.

Case renames:

  • v1 API benchmarks: series=N, dp=N, op=marshal|unmarshal, type=floats|histograms, encoder=json|jsonv2|jsoniter
  • API client: size=NKB
  • promhttp: op=<name>,size=<name>
  • counter vec table: labels=<shape>,constraint=<yes|no>

Verification: go vet ./api/... ./prometheus/... clean; smoke runs of the migrated benchmarks (-benchtime=50x) and the full go 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

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
radianceded force-pushed the modernize-microbenchmarks branch from 655030e to 35aa9ae Compare September 10, 2026 10:52
@radianceded

Copy link
Copy Markdown
Contributor Author

DCO signed in 35aa9ae — thanks for the review!

@bwplotka
bwplotka merged commit 5a4ff97 into prometheus:main Sep 10, 2026
15 checks passed
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.

chore: Modernize micro benchmarks

2 participants