This commit is contained in:
Aliaksandr Valialkin 2024-04-28 22:15:27 +02:00
parent d724da794f
commit 59b7bef051
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -296,15 +296,21 @@ type statsPipeProcessorShardNopad struct {
columnIdxs []int columnIdxs []int
keyBuf []byte keyBuf []byte
keyBufPrev []byte
spgPrev *statsPipeGroup
stateSizeBudget int stateSizeBudget int
} }
func (shard *statsPipeProcessorShard) getStatsPipeGroup(key []byte) *statsPipeGroup { func (shard *statsPipeProcessorShard) getStatsPipeGroup(key []byte) *statsPipeGroup {
spg := shard.m[string(key)] if shard.spgPrev != nil && string(shard.keyBufPrev) == string(key) {
if spg != nil { // Fast path - return the spg for the same key.
return spg return shard.spgPrev
} }
// Slow path - locate spg by key.
spg := shard.m[string(key)]
if spg == nil {
sfps := make([]statsFuncProcessor, len(shard.funcs)) sfps := make([]statsFuncProcessor, len(shard.funcs))
for i, f := range shard.funcs { for i, f := range shard.funcs {
sfp, stateSize := f.newStatsFuncProcessor() sfp, stateSize := f.newStatsFuncProcessor()
@ -316,6 +322,10 @@ func (shard *statsPipeProcessorShard) getStatsPipeGroup(key []byte) *statsPipeGr
} }
shard.m[string(key)] = spg shard.m[string(key)] = spg
shard.stateSizeBudget -= len(key) + int(unsafe.Sizeof("")+unsafe.Sizeof(spg)+unsafe.Sizeof(sfps[0])*uintptr(len(sfps))) shard.stateSizeBudget -= len(key) + int(unsafe.Sizeof("")+unsafe.Sizeof(spg)+unsafe.Sizeof(sfps[0])*uintptr(len(sfps)))
}
shard.keyBufPrev = append(shard.keyBufPrev[:0], key...)
shard.spgPrev = spg
return spg return spg
} }