Skip to content

Thread byte writes through buffered writers - #126

Draft
fvallenilla wants to merge 1 commit into
pr/line-protocol-builderfrom
pr/writebytes-path
Draft

Thread byte writes through buffered writers#126
fvallenilla wants to merge 1 commit into
pr/line-protocol-builderfrom
pr/writebytes-path

Conversation

@fvallenilla

@fvallenilla fvallenilla commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • let line-protocol helpers keep their byte slices through the writer boundary via WriteBytes
  • update buffered UDP and unixgram writer paths so byte writes preserve the same buffering semantics as string writes
  • add a targeted write-path benchmark to compare Write(string) with WriteBytes([]byte) behavior

Benchmark results

Baseline: #124

name                           old time/op    new time/op    delta
CounterAddCombined-12            510.1ns       478.4ns       -6.21%
CounterAddCombinedPostGC-12      585.6ns       595.5ns          ~
geomean                          546.5ns       533.7ns       -2.35%

name                           old B/op       new B/op      delta
CounterAddCombined-12             768.0         592.0       -22.92%
CounterAddCombinedPostGC-12       769.0         593.0       -22.89%
geomean                           768.5         592.5       -22.90%

name                           old allocs/op  new allocs/op delta
CounterAddCombined-12              5.000         4.000      -20.00%
CounterAddCombinedPostGC-12        5.000         4.000      -20.00%
geomean                             5.000         4.000      -20.00%

Test plan

  • go test ./spectator/meter
  • go test ./spectator/writer -run '^$'
  • go test ./spectator/meter -run '^$' -bench 'BenchmarkCounterAddCombined$|BenchmarkCounterAddCombinedPostGC$' -benchmem -count=10
  • go test ./spectator/meter -run '^$' -bench 'BenchmarkWriteLineInt(Current|Bytes)' -benchmem -count=1

Made with Cursor

Preserve the byte-oriented hot path while keeping buffered string writes allocation-free and making buffer flushes target explicit raw socket sinks, so the writer stack stays fast and the recursion hazard stays covered by tests.

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