From 8744aebdfa177bd82f45431700d995fccca7890c Mon Sep 17 00:00:00 2001 From: Artur Melanchyk Date: Tue, 7 Jan 2025 14:17:19 +0100 Subject: [PATCH] Single matrix memory allocation in DeserializeCMS (#1391) Signed-off-by: Artur Melanchyk --- internal/eval/countminsketch.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/eval/countminsketch.go b/internal/eval/countminsketch.go index 116531bfb..433d006cb 100644 --- a/internal/eval/countminsketch.go +++ b/internal/eval/countminsketch.go @@ -307,8 +307,9 @@ func DeserializeCMS(buffer *bytes.Reader) (*CountMinSketch, error) { // Read matrix matrix := make([][]uint64, depth) + flatMatrix := make([]uint64, depth*width) // single memory allocation for i := 0; i < int(depth); i++ { - matrix[i] = make([]uint64, width) + matrix[i] = flatMatrix[i*int(width) : (i+1)*int(width) : (i+1)*int(width)] for j := 0; j < int(width); j++ { if err := binary.Read(buffer, binary.BigEndian, &matrix[i][j]); err != nil { return nil, err