[#424] object: Do not store large slices in pool

Dynamically growing an unbounded buffers can cause a large
amount of memory to be pinned and never be freed.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
pull/440/head
Dmitrii Stepanov 2023-06-02 17:33:51 +03:00 committed by Evgenii Stratonikov
parent 41ab4d070e
commit 0400153b7d
1 changed files with 7 additions and 1 deletions

View File

@ -4,7 +4,10 @@ import (
"sync"
)
const defaultAllocSize = 1024
const (
defaultAllocSize = 1024
poolSliceMaxSize = 128 * 1024
)
type payload struct {
Data []byte
@ -19,6 +22,9 @@ func getPayload() *payload {
}
func putPayload(p *payload) {
if cap(p.Data) > poolSliceMaxSize {
return
}
p.Data = p.Data[:0]
putBytesPool.Put(p)
}