Skip to content

Commit

Permalink
Single matrix memory allocation in DeepCopy (#1390)
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 9723444 commit c7e9710
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 @@ -199,8 +199,9 @@ func (c *CountMinSketch) DeepCopy() *CountMinSketch {

// Deep copy the matrix
matrix := make([][]uint64, c.opts.depth)
flatMatrix := make([]uint64, c.opts.depth*c.opts.width) // single memory allocation
for row := uint64(0); row < c.opts.depth; row++ {
matrix[row] = make([]uint64, c.opts.width)
matrix[row] = flatMatrix[row*c.opts.width : (row+1)*c.opts.width : (row+1)*c.opts.width]
copy(matrix[row], c.matrix[row])
}

Expand Down

0 comments on commit c7e9710

Please sign in to comment.