Skip to content

Improve on toSpectatorId#119

Merged
copperlight merged 1 commit intoNetflix:mainfrom
fvallenilla:id-builder
Jul 10, 2025
Merged

Improve on toSpectatorId#119
copperlight merged 1 commit intoNetflix:mainfrom
fvallenilla:id-builder

Conversation

@fvallenilla
Copy link
Copy Markdown
Contributor

The existing implementation when creating a NewId generates a significant amount of allocations due to concatenating strings in toSpectatorId.

This commit moves it to using a strings.Builder.

goos: darwin
goarch: arm64
pkg: github.com/Netflix/spectator-go/v2/spectator/meter
cpu: Apple M3 Pro
BenchmarkToSpectatorId-12         9054499   1323 ns/op 1290 B/op 40 allocs/op
BenchmarkToSpectatorIdBuilder-12 18567895  656.0 ns/op  504 B/op  6 allocs/op

The existing implementation generates a significant amount of
allocations due to concatenating strings. This commit moves it to using
a strings.Builder.

```
goos: darwin
goarch: arm64
pkg: github.com/Netflix/spectator-go/v2/spectator/meter
cpu: Apple M3 Pro
BenchmarkToSpectatorId-12         9054499   1323 ns/op 1290 B/op 40 allocs/op
BenchmarkToSpectatorIdBuilder-12 18567895  656.0 ns/op  504 B/op  6 allocs/op
```
@fvallenilla fvallenilla requested a review from copperlight July 10, 2025 18:36
Copy link
Copy Markdown
Collaborator

@copperlight copperlight left a comment

Choose a reason for hiding this comment

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

This is very nice change - it is tight, and it directly addresses the string performance issue, without altering the overall design. Thank you for the contribution, and the benchmark demonstrating the performance improvement. 👏🏻

I have another larger change in-flight to add LowLatencyBuffers, which will also help overall processing time when recording metrics in highly concurrent applications.

This change will get tagged with that change.

@copperlight copperlight merged commit 7b1dba3 into Netflix:main Jul 10, 2025
2 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.

2 participants