From 59b7bef051ac43d8dd6359104d6d1f9697ad9528 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 28 Apr 2024 22:15:27 +0200 Subject: [PATCH] wip --- lib/logstorage/pipes.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/logstorage/pipes.go b/lib/logstorage/pipes.go index 629519174..92f89d49c 100644 --- a/lib/logstorage/pipes.go +++ b/lib/logstorage/pipes.go @@ -296,26 +296,36 @@ type statsPipeProcessorShardNopad struct { columnIdxs []int keyBuf []byte + keyBufPrev []byte + spgPrev *statsPipeGroup stateSizeBudget int } func (shard *statsPipeProcessorShard) getStatsPipeGroup(key []byte) *statsPipeGroup { + if shard.spgPrev != nil && string(shard.keyBufPrev) == string(key) { + // Fast path - return the spg for the same key. + return shard.spgPrev + } + + // Slow path - locate spg by key. spg := shard.m[string(key)] - if spg != nil { - return spg + if spg == nil { + sfps := make([]statsFuncProcessor, len(shard.funcs)) + for i, f := range shard.funcs { + sfp, stateSize := f.newStatsFuncProcessor() + sfps[i] = sfp + shard.stateSizeBudget -= stateSize + } + spg = &statsPipeGroup{ + sfps: sfps, + } + shard.m[string(key)] = spg + shard.stateSizeBudget -= len(key) + int(unsafe.Sizeof("")+unsafe.Sizeof(spg)+unsafe.Sizeof(sfps[0])*uintptr(len(sfps))) } - sfps := make([]statsFuncProcessor, len(shard.funcs)) - for i, f := range shard.funcs { - sfp, stateSize := f.newStatsFuncProcessor() - sfps[i] = sfp - shard.stateSizeBudget -= stateSize - } - spg = &statsPipeGroup{ - sfps: sfps, - } - shard.m[string(key)] = spg - 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 }