[#425] object: Do not store large slices in pool
ci/woodpecker/pr/pre-commit Pipeline was successful
Details
ci/woodpecker/pr/pre-commit Pipeline was successful
Details
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/425/head
parent
405e17b2ec
commit
25bedab91a
|
@ -4,7 +4,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultAllocSize = 1024
|
const (
|
||||||
|
defaultAllocSize = 1024
|
||||||
|
poolSliceMaxSize = 128 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
type payload struct {
|
type payload struct {
|
||||||
Data []byte
|
Data []byte
|
||||||
|
@ -19,6 +22,9 @@ func getPayload() *payload {
|
||||||
}
|
}
|
||||||
|
|
||||||
func putPayload(p *payload) {
|
func putPayload(p *payload) {
|
||||||
|
if cap(p.Data) > poolSliceMaxSize {
|
||||||
|
return
|
||||||
|
}
|
||||||
p.Data = p.Data[:0]
|
p.Data = p.Data[:0]
|
||||||
putBytesPool.Put(p)
|
putBytesPool.Put(p)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue