Skip to content

arenaskl: consider alternative TrySeekingUsingNext optimizations #5358

@jbowens

Description

@jbowens

The arenaskl Iterator implementation implements the TrySeekUsingNext optimization through performing simple Nexts:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions