From 14786d92d138b2dee1fde1e17e27b4f7de96a6bf Mon Sep 17 00:00:00 2001 From: Artur Melanchyk Date: Sat, 18 Jan 2025 19:15:01 +0100 Subject: [PATCH] perf(algo): single memory allocation in NewCountMinSketch Signed-off-by: Artur Melanchyk --- algo/cm-sketch.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algo/cm-sketch.go b/algo/cm-sketch.go index 85dde19418c..4e02cda6118 100644 --- a/algo/cm-sketch.go +++ b/algo/cm-sketch.go @@ -78,8 +78,9 @@ func NewCountMinSketch(epsilon, delta float64) *CountMinSketch { matrix = make([][]uint64, depth) ) + flatMatrix := make([]uint64, width*depth) for i := uint(0); i < depth; i++ { - matrix[i] = make([]uint64, width) + matrix[i] = flatMatrix[i*width : (i+1)*width : (i+1)*width] } return &CountMinSketch{