Skip to content

Commit

Permalink
buffer: restore dropping of too large buffers
Browse files Browse the repository at this point in the history
This was removed when introducing sync.Pool in commit
1a1367c because it seemed unnecessary, but an
open issue about the sync.Pool documentation shows that a size limit may be
useful after all.
  • Loading branch information
pohly committed Feb 2, 2023
1 parent 1025055 commit 2582956
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ func GetBuffer() *Buffer {

// PutBuffer returns a buffer to the free list.
func PutBuffer(b *Buffer) {
if b.Len() >= 256 {
// Let big buffers die a natural death, without relying on
// sync.Pool behavior. The documentation implies that items may
// get deallocated while stored there ("If the Pool holds the
// only reference when this [= be removed automatically]
// happens, the item might be deallocated."), but
// https://github.com/golang/go/issues/23199 leans more towards
// having such a size limit.
return
}

buffers.Put(b)
}

Expand Down

0 comments on commit 2582956

Please sign in to comment.