Skip to content
Prev Previous commit
Next Next commit
Use non sparse HLL to avoid allocations
  • Loading branch information
jeschkies committed Dec 27, 2024
commit 448aafe83823fdca175e1e817be5b241edc0fea2
3 changes: 1 addition & 2 deletions pkg/logql/count_min_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ func (v *HeapCountMinSketchVector) Push(x any) {
func (v *HeapCountMinSketchVector) Pop() any {
old := v.Metrics
n := len(old)
x := old[n-1]
v.Metrics = old[0 : n-1]
return x
return old[n-1]
}

// JoinCountMinSketchVector joins the results from stepEvaluator into a CountMinSketchVector.
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/sketch/cms.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewCountMinSketch(w, d uint32) (*CountMinSketch, error) {
Depth: d,
Width: w,
Counters: make2dslice(w, d),
HyperLogLog: hyperloglog.New16(),
HyperLogLog: hyperloglog.New16NoSparse(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave a comment.

// Sparse HLL sketches should result in less memory usage for cardinalities of 100k or less but the automatic transition from sparse
// to non-sparse sketches above that cardinality range results in significantly more memory allocs/bytes. 
// Until we have a reliable way of estimating the cardinality set in advance, always use non-sparse for faster performance.
}, nil
}

Expand Down
Loading