mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/mergeset: optimize Set.AddMulti() a bit for len(items) < 10000
This should improve the search speed for time series matching the given label filters
This commit is contained in:
parent
cdac04997a
commit
c0a9b87f46
1 changed files with 17 additions and 10 deletions
|
@ -814,21 +814,23 @@ func (b *bucket16) add(x uint16) bool {
|
|||
}
|
||||
|
||||
func (b *bucket16) addMulti(a []uint64) int {
|
||||
count := 0
|
||||
if b.bits == nil {
|
||||
if b.smallPoolLen + len(a) > len(b.smallPool) {
|
||||
b.switchSmallPoolToBits()
|
||||
goto fastPath
|
||||
}
|
||||
// Slow path
|
||||
for i, x := range a {
|
||||
if b.add(uint16(x)) {
|
||||
count := 0
|
||||
for _, x := range a {
|
||||
if b.addToSmallPool(uint16(x)) {
|
||||
count++
|
||||
}
|
||||
if b.bits != nil {
|
||||
a = a[i+1:]
|
||||
goto fastPath
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
fastPath:
|
||||
count := 0
|
||||
bits := b.bits
|
||||
for _, x := range a {
|
||||
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
||||
|
@ -850,14 +852,19 @@ func (b *bucket16) addToSmallPool(x uint16) bool {
|
|||
b.smallPoolLen++
|
||||
return true
|
||||
}
|
||||
b.switchSmallPoolToBits()
|
||||
b.add(x)
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *bucket16) switchSmallPoolToBits() {
|
||||
smallPoolLen := b.smallPoolLen
|
||||
b.smallPoolLen = 0
|
||||
var bits [wordsPerBucket]uint64
|
||||
b.bits = &bits
|
||||
for _, v := range sp[:] {
|
||||
for _, v := range b.smallPool[:smallPoolLen] {
|
||||
b.add(v)
|
||||
}
|
||||
b.add(x)
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *bucket16) has(x uint16) bool {
|
||||
|
|
Loading…
Reference in a new issue