Skip to content

Reduce meter line formatting allocations#124

Draft
fvallenilla wants to merge 1 commit intomainfrom
pr/line-protocol-builder
Draft

Reduce meter line formatting allocations#124
fvallenilla wants to merge 1 commit intomainfrom
pr/line-protocol-builder

Conversation

@fvallenilla
Copy link
Copy Markdown
Contributor

Summary

  • route meter writes through shared line-protocol helpers instead of per-call fmt.Sprintf
  • switch spectatord ID construction to a pooled byte builder while keeping Id map-backed in this first step
  • add hot-path benchmarks for NewId -> NewCounter -> Add

Benchmark results

Baseline: main

name                           old time/op    new time/op    delta
CounterAddCombined-12           1020.0ns       500.1ns      -50.97%
CounterAddCombinedPostGC-12     1107.5ns       585.8ns      -47.11%
ToSpectatorIdBuilder-12          731.6ns       338.9ns      -53.69%
geomean                          938.5ns       463.0ns      -50.66%

name                           old B/op       new B/op      delta
CounterAddCombined-12            1128.0         768.0       -31.91%
CounterAddCombinedPostGC-12      1130.0         769.0       -31.95%
ToSpectatorIdBuilder-12           504.0         176.0       -65.08%
geomean                           862.9         470.2       -45.51%

name                           old allocs/op  new allocs/op delta
CounterAddCombined-12             12.000         5.000      -58.33%
CounterAddCombinedPostGC-12       12.000         5.000      -58.33%
ToSpectatorIdBuilder-12            6.000         1.000      -83.33%
geomean                            9.524         2.924      -69.30%

Test plan

  • go test ./spectator/meter
  • go test ./spectator/meter -run '^$' -bench 'BenchmarkCounterAddCombined$|BenchmarkCounterAddCombinedPostGC$|BenchmarkToSpectatorIdBuilder$' -benchmem -count=10

Made with Cursor

Switch hot meter writes to shared line-protocol helpers and use a pooled byte builder for spectatord IDs so the baseline write path allocates less before changing Id internals.

Made-with: Cursor
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.

1 participant