Skip to content

datadog: add fast path for serializer - #213

Merged
kevinburkesegment merged 1 commit into
mainfrom
benchmarks
Nov 22, 2025
Merged

kevinburkesegment merged 1 commit into
mainfrom
benchmarks

Conversation

@kevinburkesegment

Copy link
Copy Markdown
Contributor

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

Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
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
Copy Markdown
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 thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer.go Outdated
Comment thread datadog/serializer_test.go Outdated
Comment on lines +577 to +578
b.ResetTimer()
for i := 0; i < b.N; i++ {

Copy link
Copy Markdown
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 thread datadog/serializer_test.go Outdated
Comment on lines +605 to +607
cutset := "._-"
b.ResetTimer()
for i := 0; i < b.N; i++ {

Copy link
Copy Markdown
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() {

@extemporalgenome extemporalgenome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@extemporalgenome extemporalgenome left a comment

Copy link
Copy Markdown
Contributor

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.

2 participants