Skip to content

Commit

Permalink
perf: fix operation in seek (#2077)
Browse files Browse the repository at this point in the history
Copy of #1719

Co-authored-by: Ziyuan Zhong <[email protected]>
  • Loading branch information
harshil-goel and zzyalbert committed Aug 14, 2024
1 parent 17f28fc commit 2c148fe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func (it *Iterator) Next() {

// Set next item to current
it.item = it.data.pop()
for it.iitr.Valid() {
for it.iitr.Valid() && hasPrefix(it.iitr, it.opt.Prefix) {
if it.parseItem() {
// parseItem calls one extra next.
// This is used to deal with the complexity of reverse iteration.
Expand Down Expand Up @@ -725,6 +725,13 @@ func (it *Iterator) fill(item *Item) {
}
}

func hasPrefix(it y.Iterator, prefix []byte) bool {
if len(prefix) > 0 {
return bytes.HasPrefix(y.ParseKey(it.Key()), prefix)
}
return true
}

func (it *Iterator) prefetch() {
prefetchSize := 2
if it.opt.PrefetchValues && it.opt.PrefetchSize > 1 {
Expand All @@ -734,7 +741,7 @@ func (it *Iterator) prefetch() {
i := it.iitr
var count int
it.item = nil
for i.Valid() {
for i.Valid() && hasPrefix(i, it.opt.Prefix) {
if !it.parseItem() {
continue
}
Expand Down

0 comments on commit 2c148fe

Please sign in to comment.