Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fjall-rs/lsm-tree
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: fjall-rs/lsm-tree
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: perf/mvcc-drain-min
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 6, 2024

  1. perf: try to improve drain_key_min perf

    needs benchmarking
    marvin-j97 committed Dec 6, 2024
    Copy the full SHA
    e80f21e View commit details

Commits on Dec 7, 2024

  1. Copy the full SHA
    2e5d3f9 View commit details
Showing with 16 additions and 31 deletions.
  1. +16 −31 src/mvcc_stream.rs
47 changes: 16 additions & 31 deletions src/mvcc_stream.rs
Original file line number Diff line number Diff line change
@@ -11,40 +11,18 @@ use double_ended_peekable::{DoubleEndedPeekable, DoubleEndedPeekableExt};
#[allow(clippy::module_name_repetitions)]
pub struct MvccStream<I: DoubleEndedIterator<Item = crate::Result<InternalValue>>> {
inner: DoubleEndedPeekable<I>,

lo_last_seen_key: Option<UserKey>,
}

impl<I: DoubleEndedIterator<Item = crate::Result<InternalValue>>> MvccStream<I> {
/// Initializes a new merge iterator
#[must_use]
pub fn new(iter: I) -> Self {
let iter = iter.double_ended_peekable();
Self { inner: iter }
}

fn drain_key_min(&mut self, key: &UserKey) -> crate::Result<()> {
loop {
let Some(next) = self.inner.peek() else {
return Ok(());
};

let Ok(next) = next else {
// NOTE: We just asserted, the peeked value is an error
#[allow(clippy::expect_used)]
return Err(self
.inner
.next()
.expect("should exist")
.expect_err("should be error"));
};

// Consume version
if next.key.user_key == key {
// NOTE: We know the next value is not empty, because we just peeked it
#[allow(clippy::expect_used)]
self.inner.next().expect("should not be empty")?;
} else {
return Ok(());
}
Self {
inner: iter,
lo_last_seen_key: None,
}
}
}
@@ -53,12 +31,19 @@ impl<I: DoubleEndedIterator<Item = crate::Result<InternalValue>>> Iterator for M
type Item = crate::Result<InternalValue>;

fn next(&mut self) -> Option<Self::Item> {
let head = fail_iter!(self.inner.next()?);
loop {
let head = fail_iter!(self.inner.next()?);

// As long as items are the same key, ignore them
fail_iter!(self.drain_key_min(&head.key.user_key));
if let Some(last_seen_key) = &self.lo_last_seen_key {
if head.key.user_key == last_seen_key {
continue;
}
}

self.lo_last_seen_key = Some(head.key.user_key.clone());

Some(Ok(head))
return Some(Ok(head));
}
}
}