From ac2185f8228b35047ba5d7b3906d53f54a25cfe1 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 27 Jul 2022 15:59:21 -0400 Subject: [PATCH] requestbatcher: nil unused slice entries in batchQueue heap 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`. --- pkg/internal/client/requestbatcher/batcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/internal/client/requestbatcher/batcher.go b/pkg/internal/client/requestbatcher/batcher.go index 4407c7233ae9..d4397dd1908a 100644 --- a/pkg/internal/client/requestbatcher/batcher.go +++ b/pkg/internal/client/requestbatcher/batcher.go @@ -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) } @@ -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