fjall-rs / lsm-tree

K.I.S.S. LSM-tree implementation in safe Rust
https://fjall-rs.github.io/
Apache License 2.0
80 stars 5 forks source link

Optimize open range read reader collection #56

Closed marvin-j97 closed 1 week ago

marvin-j97 commented 1 month ago

Build on top of https://github.com/fjall-rs/lsm-tree/issues/55

Right now, when a (partially) open range is used, for high segment counts, a lot of Arc clones will be called (O(n)), which can be a bottleneck for functions like Tree::first_key_value, Tree::last_key_value.

Right now, each disjoint level may be clone-collected fully because the level cannot be cloned itself. image

The multi segment reading needs to be overhauled, by instead only cloning an Arc<Level>, and lazily initializing a new SegmentReader once the current has run out, that way we only clone up to 6 times (once per level). Because it is double-ended, it will need to use two pointers, kind of like ValueBlockConsumer. This will need a change in the level manifest, to make each level wrapped in an Arc - when locking the level manifest, Arc::get_mut should be possible to use to mutate the levels.

image

Range culling can then be implemented by just setting the lo and hi offsets.

For disjoint tree, the readers should be collected, so there's a single reader containing the (7) level readers.