Skip to content

Commit

Permalink
Reuse buffer for str fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacorts committed Dec 5, 2023
1 parent 6e05bf6 commit 80ea4d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/logproto/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,13 @@ func (m *FilterChunkRefRequest) GetStep() int64 {
// GetQuery returns the query of the request.
// The query is the hash for the input chunks refs and the filter expressions.
func (m *FilterChunkRefRequest) GetQuery() string {
var encodeBuf []byte
var chunksHash uint64
if len(m.Refs) > 0 {
h := xxhash.New()
for _, ref := range m.Refs {
_, _ = h.WriteString(fmt.Sprintf("%s-%d", ref.Tenant, ref.Fingerprint))
encodeBuf = encodeBuf[:0]
_, _ = h.Write(fmt.Appendf(encodeBuf, "%d", ref.Fingerprint))
}
chunksHash = h.Sum64()
}
Expand All @@ -375,7 +377,8 @@ func (m *FilterChunkRefRequest) GetQuery() string {
if i > 0 {
sb.WriteString(",")
}
sb.WriteString(strconv.Itoa(int(filter.Operator)))
encodeBuf = encodeBuf[:0]
sb.WriteString(string(fmt.Appendf(encodeBuf, "%d", filter.Operator)))
sb.WriteString("-")
sb.WriteString(filter.Match)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/logproto/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) {
},
},
},
expected: `10379275979514026197`,
expected: `13237225503670494420`,
},
{
desc: "request with filters but no chunks",
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestFilterChunkRefRequestGetQuery(t *testing.T) {
},
},
},
expected: `8320232433975427174/0-uuid,1-trace`,
expected: `6080128442901703586/0-uuid,1-trace`,
},
} {
t.Run(tc.desc, func(t *testing.T) {
Expand Down

0 comments on commit 80ea4d8

Please sign in to comment.