From 2ecb117082dcc2e374ef26abeabe2be2ec21a4bf Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 29 Jun 2019 13:48:29 +0300 Subject: [PATCH] lib/storage: skip non-matching metricIDs in sortedFilter This should improve performance for big sorteFilter lists. --- lib/storage/index_db.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index d76fb1c64..5f765a49a 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -1678,6 +1678,15 @@ func (is *indexSearch) updateMetricIDsForOrSuffixWithFilter(prefix []byte, metri } metricID := encoding.UnmarshalUint64(v) if metricID != nextMetricID { + // Skip metricIDs smaller than the found metricID, since they don't + // match anything. + if len(sortedFilter) > 0 && metricID > sortedFilter[0] { + sortedFilter = sortedFilter[1:] + n := sort.Search(len(sortedFilter), func(i int) bool { + return metricID <= sortedFilter[i] + }) + sortedFilter = sortedFilter[n:] + } continue } if isNegative {