Skip to content

Commit

Permalink
Single matrix memory allocation in DeserializeCMS (#1391)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Melanchyk <[email protected]>
  • Loading branch information
arturmelanchyk authored Jan 7, 2025
1 parent cc64b05 commit 8744aeb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/eval/countminsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8744aeb

Please sign in to comment.