From cc1c677d7b72a99f8e89c28efb9fbc13d4c59d4c Mon Sep 17 00:00:00 2001 From: taisho6339 Date: Fri, 29 Oct 2021 11:04:49 +0900 Subject: [PATCH] Improve complexity of getting all fingerprints --- pkg/ingester/index/index.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/ingester/index/index.go b/pkg/ingester/index/index.go index 7b689c014121..537ea9a700aa 100644 --- a/pkg/ingester/index/index.go +++ b/pkg/ingester/index/index.go @@ -319,16 +319,24 @@ func (shard *indexShard) allFPs() model.Fingerprints { shard.mtx.RLock() defer shard.mtx.RUnlock() - var result model.Fingerprints + var fps model.Fingerprints for _, ie := range shard.idx { for _, ive := range ie.fps { - result = intersect(result, ive.fps) + fps = append(fps, ive.fps...) } - sort.Sort(result) } - if len(result) == 0 { + if len(fps) == 0 { return nil } + + var result model.Fingerprints + var m = map[model.Fingerprint]struct{}{} + for _, fp := range fps { + if _, ok := m[fp]; !ok { + m[fp] = struct{}{} + result = append(result, fp) + } + } return result }