mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
be39414f9c
commit
c23b66a1ad
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue