-
Notifications
You must be signed in to change notification settings - Fork 512
Open
Description
The arenaskl Iterator implementation implements the TrySeekUsingNext optimization through performing simple Nexts:
pebble/internal/arenaskl/iterator.go
Lines 94 to 115 in 6c6fd75
| if flags.TrySeekUsingNext() { | |
| if it.nd == it.list.tail || it.nd == it.upperNode { | |
| // Iterator is done. | |
| return nil | |
| } | |
| less := it.list.cmp(it.kv.K.UserKey, key) < 0 | |
| // Arbitrary constant. By measuring the seek cost as a function of the | |
| // number of elements in the skip list, and fitting to a model, we | |
| // could adjust the number of nexts based on the current size of the | |
| // skip list. | |
| const numNexts = 5 | |
| kv := &it.kv | |
| for i := 0; less && i < numNexts; i++ { | |
| if kv = it.Next(); kv == nil { | |
| // Iterator is done. | |
| return nil | |
| } | |
| less = it.list.cmp(kv.K.UserKey, key) < 0 | |
| } | |
| if !less { | |
| return kv | |
| } |
If it doesn't find the sought key within 5 nexts, it abandons the work it's already done and starts anew. We could instead take advantage of the skiplist node structure and try advancing at levels above the base level but below the list height.
I'm imagining something like:
Initialize level = 0
for range 5 {
next := n.tower[level]
if key <= next.key {
return searchDescending(next, level, key)
}
n = next
if n.height > level+1 {
level++
}
}
Jira issue: PEBBLE-1197