Skip to content

Commit

Permalink
Storage: reduce memory allocations when merging series sets (promethe…
Browse files Browse the repository at this point in the history
…us#12938)

Instead of setting to nil and allocating a new slice every time the
merge is advanced, re-use the previous slice.
This is safe because the `currentSets` member is only used inside member
functions, and explicitly copied in `At()`, the only place it leaves the
struct.

Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham authored Oct 6, 2023
1 parent b8f8c3c commit a5a4eab
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion storage/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (c *genericMergeSeriesSet) Next() bool {
}

// Now, pop items of the heap that have equal label sets.
c.currentSets = nil
c.currentSets = c.currentSets[:0]
c.currentLabels = c.heap[0].At().Labels()
for len(c.heap) > 0 && labels.Equal(c.currentLabels, c.heap[0].At().Labels()) {
set := heap.Pop(&c.heap).(genericSeriesSet)
Expand Down

0 comments on commit a5a4eab

Please sign in to comment.