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

perf: preallocate GroupID #2441

Merged
merged 3 commits into from
Dec 2, 2020
Merged

perf: preallocate GroupID #2441

merged 3 commits into from
Dec 2, 2020

Conversation

docmerlin
Copy link
Contributor

No description provided.

@@ -87,6 +87,17 @@ func ToGroupID(name string, tags map[string]string, dims Dimensions) GroupID {
return NilGroup
}
var buf strings.Builder
l := 0
if dims.ByName {
l += len(name) + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused about why these values were used until I looked below at the WriteString / WriteRune calls. Would it be overkill to add comments here that show the corresponding values added to buf? i.e.:

if dims.ByName {
  // add capacity for (name + \n)
  l += len(name) + 1
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

better comments around peallocating GroupID
@docmerlin docmerlin merged commit 81be964 into master Dec 2, 2020
@docmerlin docmerlin deleted the preallocate_groupid branch December 2, 2020 22:37
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