Skip to content

perf: reduce meter allocations#123

Closed
fvallenilla wants to merge 3 commits intomainfrom
autoresearch/reduce-allocs-2026-03-25
Closed

perf: reduce meter allocations#123
fvallenilla wants to merge 3 commits intomainfrom
autoresearch/reduce-allocs-2026-03-25

Conversation

@fvallenilla
Copy link
Copy Markdown
Contributor

@fvallenilla fvallenilla commented Mar 25, 2026

Summary

  • Reduce meter.Id construction overhead by replacing escaped tag maps with a lower-allocation internal representation and pooling spectatord id formatting buffers
  • Replace per-meter fmt.Sprintf line construction with pooled strconv.Append* helpers shared across meter types
  • Keep the follow-up readability cleanup separate while preserving the large runtime and allocation win versus main

Benchstat

Against main using the same temporary benchmark harness for both trees (-count=10 -cpu 1) on darwin/arm64 (Apple M3 Pro):

Time:

Benchmark main current PR vs base
NewId 1269.0ns 392.5ns -69.07%
CombinedBenchmark 1366.5ns 433.2ns -68.30%

Bytes:

Benchmark main current PR vs base
NewId B/op 920 432 -53.04%
CombinedBenchmark B/op 1128 608 -46.10%

Allocations:

Benchmark main current PR vs base
NewId allocs 9 3 -66.67%
CombinedBenchmark allocs 12 4 -66.67%

Test plan

  • go test ./spectator/meter ./spectator/writer
  • targeted meter benchmarks for NewId, combined benchmark coverage, post-GC behavior, and spectatord id formatting during development
  • benchstat comparison against main showing substantial wins in wall-clock, bytes/op, and allocs/op

@fvallenilla fvallenilla force-pushed the autoresearch/reduce-allocs-2026-03-25 branch from 0cb0dbf to a8d596a Compare March 25, 2026 21:24
@fvallenilla fvallenilla changed the title perf: reduce meter hot-path allocations perf: reduce meter allocations Mar 25, 2026
Replace escaped tag maps in `meter.Id` with a lower-allocation internal representation and pool spectatord id formatting buffers to cut `NewId` allocations substantially.

Made-with: Cursor
Replace per-meter `fmt.Sprintf` calls with shared pooled `strconv.Append*` helpers and add combined benchmark coverage, including a post-GC variant for pool repopulation behavior.

Made-with: Cursor
Use explicit tag pairs and shared line-prefix helpers to make the meter internals easier to follow while preserving the large allocation and runtime win versus main.

Made-with: Cursor
@fvallenilla fvallenilla force-pushed the autoresearch/reduce-allocs-2026-03-25 branch from a8d596a to 584129e Compare March 26, 2026 00:24
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