mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-01 15:33:35 +00:00
lib/mergeset: pre-allocate data and items for inmemoryBlock in order to reduce memory allocations under high churn rate
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2007
This commit is contained in:
parent
02b2bfcff3
commit
d8d59ff760
1 changed files with 4 additions and 3 deletions
|
@ -117,9 +117,10 @@ func (ib *inmemoryBlock) Add(x []byte) bool {
|
||||||
if len(x)+len(data) > maxInmemoryBlockSize {
|
if len(x)+len(data) > maxInmemoryBlockSize {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if cap(data) < maxInmemoryBlockSize {
|
if cap(data) == 0 {
|
||||||
dataLen := len(data)
|
// Pre-allocate data and items in order to reduce memory allocations
|
||||||
data = bytesutil.ResizeWithCopyNoOverallocate(data, maxInmemoryBlockSize)[:dataLen]
|
data = make([]byte, 0, maxInmemoryBlockSize)
|
||||||
|
ib.items = make([]Item, 0, 512)
|
||||||
}
|
}
|
||||||
dataLen := len(data)
|
dataLen := len(data)
|
||||||
data = append(data, x...)
|
data = append(data, x...)
|
||||||
|
|
Loading…
Reference in a new issue