mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +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
4bdd10ab90
commit
9c62b25ad6
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 {
|
||||
return false
|
||||
}
|
||||
if cap(data) < maxInmemoryBlockSize {
|
||||
dataLen := len(data)
|
||||
data = bytesutil.ResizeWithCopyNoOverallocate(data, maxInmemoryBlockSize)[:dataLen]
|
||||
if cap(data) == 0 {
|
||||
// Pre-allocate data and items in order to reduce memory allocations
|
||||
data = make([]byte, 0, maxInmemoryBlockSize)
|
||||
ib.items = make([]Item, 0, 512)
|
||||
}
|
||||
dataLen := len(data)
|
||||
data = append(data, x...)
|
||||
|
|
Loading…
Reference in a new issue