frostfs-api-go/util/signature/buffer.go
Dmitrii Stepanov 4cb0068dde [#37] signature: Increase pool max object size
According to the results of profiling, objects with a size of 72KB
are mainly allocated.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-06-02 17:20:24 +03:00

29 lines
465 B
Go

package signature
import "sync"
const poolSliceMaxSize = 128 * 1024
var buffersPool = sync.Pool{
New: func() any {
return make([]byte, 0)
},
}
func newBufferFromPool(size int) []byte {
result := buffersPool.Get().([]byte)
if cap(result) < size {
result = make([]byte, size)
} else {
result = result[:size]
}
return result
}
func returnBufferToPool(buf []byte) {
if cap(buf) > poolSliceMaxSize {
return
}
buf = buf[:0]
buffersPool.Put(buf)
}