Skip to content

Commit

Permalink
requestbatcher: nil unused slice entries in batchQueue heap
Browse files Browse the repository at this point in the history
This change nils out unused entries in the batchQueue's slice when the
slice is truncated to avoid retaining references to batches of requests
and preventing them from being GCed.

The change also removes a redundant update of the batchQueue's byRange
map. The `delete` was redundant because `heap.Remove` already calls `Pop`.
  • Loading branch information
nvanbenschoten committed Jul 27, 2022
1 parent eabdc49 commit ac2185f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/internal/client/requestbatcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ func (q *batchQueue) get(id roachpb.RangeID) (*batch, bool) {
}

func (q *batchQueue) remove(ba *batch) {
delete(q.byRange, ba.rangeID())
heap.Remove(q, ba.idx)
}

Expand Down Expand Up @@ -678,6 +677,7 @@ func (q *batchQueue) Push(v interface{}) {

func (q *batchQueue) Pop() interface{} {
ba := q.batches[len(q.batches)-1]
q.batches[len(q.batches)-1] = nil // for GC
q.batches = q.batches[:len(q.batches)-1]
delete(q.byRange, ba.rangeID())
ba.idx = -1
Expand Down

0 comments on commit ac2185f

Please sign in to comment.