mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-03 16:41:05 +01:00
[PERF] TSDB: ListPostings: check next item before binary search
It is fairly common that the next item is the one we want, and cheap to check. We could also start the binary search one position on, but strangely that slows it down. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
be8307db58
commit
0e1e7441e4
@ -851,15 +851,17 @@ func (it *ListPostings) Seek(x storage.SeriesRef) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Do binary search between current position and end.
|
||||
i, _ := slices.BinarySearch(it.list, x)
|
||||
if i < len(it.list) {
|
||||
it.cur = it.list[i]
|
||||
it.list = it.list[i+1:]
|
||||
return true
|
||||
i := 0 // Check the next item in the list, otherwise binary search between current position and end.
|
||||
if it.list[0] < x {
|
||||
i, _ = slices.BinarySearch(it.list, x)
|
||||
if i >= len(it.list) { // Off the end - terminate the iterator.
|
||||
it.list = nil
|
||||
return false
|
||||
}
|
||||
}
|
||||
it.list = nil
|
||||
return false
|
||||
it.cur = it.list[i]
|
||||
it.list = it.list[i+1:]
|
||||
return true
|
||||
}
|
||||
|
||||
func (*ListPostings) Err() error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user