lib/storage: pre-allocate memory for blockHeader slice in unmarshalBlockHeaders

This reduces memory usage and memory fragmentation when working with big number of time series
This commit is contained in:
Aliaksandr Valialkin 2019-08-19 12:45:43 +03:00
parent be39414f9c
commit c23b66a1ad

View file

@ -181,6 +181,10 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int)
logger.Panicf("BUG: blockHeadersCount must be greater than zero; got %d", blockHeadersCount)
}
dstLen := len(dst)
if n := dstLen + blockHeadersCount - cap(dst); n > 0 {
dst = append(dst[:cap(dst)], make([]blockHeader, n)...)
dst = dst[:dstLen]
}
var bh blockHeader
for len(src) > 0 {
tmp, err := bh.Unmarshal(src)