Skip to content

ingester: Revert stringlabels in performance critical paths #6980

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pkg/cortexpb/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func FromLabelAdaptersToLabels(ls []LabelAdapter) labels.Labels {
// Do NOT use unsafe to convert between data types because this function may
// get in input labels whose data structure is reused.
func FromLabelAdaptersToLabelsWithCopy(input []LabelAdapter) labels.Labels {
return CopyLabels(input)
return CopyLabels(FromLabelAdaptersToLabels(input))
}

// Efficiently copies labels input slice. To be used in cases where input slice
// can be reused, but long-term copy is needed.
func CopyLabels(input []LabelAdapter) labels.Labels {
builder := labels.NewBuilder(labels.EmptyLabels())
func CopyLabels(input []labels.Label) labels.Labels {
result := make(labels.Labels, len(input))

size := 0
for _, l := range input {
Expand All @@ -84,14 +84,12 @@ func CopyLabels(input []LabelAdapter) labels.Labels {
// Copy all strings into the buffer, and use 'yoloString' to convert buffer
// slices to strings.
buf := make([]byte, size)
var name, value string

for _, l := range input {
name, buf = copyStringToBuffer(l.Name, buf)
value, buf = copyStringToBuffer(l.Value, buf)
builder.Set(name, value)
for i, l := range input {
result[i].Name, buf = copyStringToBuffer(l.Name, buf)
result[i].Value, buf = copyStringToBuffer(l.Value, buf)
}
return builder.Labels()
return result
}

// Copies string to buffer (which must be big enough), and converts buffer slice containing
Expand Down
Loading