Skip to content

Conversation

@kevinburkesegment
Copy link
Contributor

In the common case where metric names/tags are all ASCII, we can copy bytes much more quickly.

Comment on lines 272 to 279
// Trim leading/trailing '.', '_' or '-'
start, end := orig, len(dst)
for start < end && isTrim(dst[start]) {
start++
}
for end > start && isTrim(dst[end-1]) {
end--
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use strings.Trim or bytes.Trim for this?

Comment on lines 577 to 578
b.ResetTimer()
for i := 0; i < b.N; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {

b.Loop is the newer, improved way to do this since 1.24, and provides a b.ResetTimer for free ahead of the first iter. See https://pkg.go.dev/testing#B.Loop

Comment on lines 605 to 607
cutset := "._-"
b.ResetTimer()
for i := 0; i < b.N; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cutset := "._-"
b.ResetTimer()
for i := 0; i < b.N; i++ {
const cutset = "._-"
for b.Loop() {

Copy link
Contributor

@extemporalgenome extemporalgenome left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@extemporalgenome extemporalgenome left a comment

Choose a reason for hiding this comment

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

LGTM

In the common case where metric names/tags are all ASCII, we can copy
bytes much more quickly.

Update some unrelated code to fix some formatting concerns and also
use the newest syntax.
@kevinburkesegment kevinburkesegment merged commit 9fcd686 into main Nov 22, 2025
9 checks passed
@kevinburkesegment kevinburkesegment deleted the benchmarks branch November 22, 2025 05:20
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.

3 participants