Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: Use strings.Builder in toMetricTagsID #219

Merged
merged 1 commit into from
Sep 7, 2021

Conversation

bmoylan
Copy link
Contributor

@bmoylan bmoylan commented Sep 7, 2021

// new
BenchmarkRegisterMetric
BenchmarkRegisterMetric/1_tag
BenchmarkRegisterMetric/1_tag-16         	 4665692	       239.6 ns/op	      96 B/op	       3 allocs/op
BenchmarkRegisterMetric/10_tag
BenchmarkRegisterMetric/10_tag-16        	 2098387	       573.9 ns/op	     616 B/op	       3 allocs/op
BenchmarkRegisterMetric/100_tag
BenchmarkRegisterMetric/100_tag-16       	  106561	     11235 ns/op	    6168 B/op	       3 allocs/op
// old
BenchmarkRegisterMetric
BenchmarkRegisterMetric/1_tag
BenchmarkRegisterMetric/1_tag-16         	 3992419	       276.9 ns/op	     120 B/op	       4 allocs/op
BenchmarkRegisterMetric/10_tag
BenchmarkRegisterMetric/10_tag-16        	 1766430	       668.3 ns/op	     728 B/op	       4 allocs/op
BenchmarkRegisterMetric/100_tag
BenchmarkRegisterMetric/100_tag-16       	  118381	     10329 ns/op	    7448 B/op	       4 allocs/op

This change is Reviewable

_, _ = buf.WriteString(name)
for _, tag := range tags {
_, _ = buf.WriteRune('|')
_, _ = buf.WriteString(tag.keyValue)
}
return metricTagsID(buf.Bytes())
return metricTagsID(buf.String())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously this bytes->string conversion required a copy

@bmoylan bmoylan merged commit f7c2552 into master Sep 7, 2021
@bmoylan bmoylan deleted the bm/metrics-string-builder branch September 7, 2021 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants