pub struct DeferredSortedIndex { /* private fields */ }Expand description
Deferred Sorted Index with LSM-style compaction
§Scan Optimization (80/20 Fix)
The original SkipMap-based scan was 3.3x slower than SQLite because:
- SkipMap iteration = pointer chasing across memory
- Each
entry.key().clone()= heap allocation - Poor cache locality (random memory access pattern)
The fix: Use a sorted Vec<Vec<u8>> for the cold storage.
- Sequential memory access = L1/L2 cache hits
- Binary search for range start = O(log N)
- Iteration = simple pointer increment
Benchmarked improvement: +50-80% scan throughput
Implementations§
Source§impl DeferredSortedIndex
impl DeferredSortedIndex
Sourcepub fn with_config(config: DeferredIndexConfig) -> Self
pub fn with_config(config: DeferredIndexConfig) -> Self
Create with custom configuration
Sourcepub fn insert(&self, key: Vec<u8>)
pub fn insert(&self, key: Vec<u8>)
Insert a key into the index
O(1) append to hot buffer (fast path)
Sourcepub fn insert_ref(&self, key: &[u8])
pub fn insert_ref(&self, key: &[u8])
Insert a key reference (avoids one clone if key is already owned)
Sourcepub fn compact(&self)
pub fn compact(&self)
Compact hot buffer into sorted storage
Merges hot buffer with existing sorted vec using k-way merge. This is O(N + M) where N = hot buffer size, M = existing sorted size.
Sourcepub fn range_from<'a>(
&'a self,
start: &[u8],
) -> impl Iterator<Item = Vec<u8>> + 'a
pub fn range_from<'a>( &'a self, start: &[u8], ) -> impl Iterator<Item = Vec<u8>> + 'a
Iterate over all keys starting from start
Uses binary search + sequential iteration for cache-friendly access.
Sourcepub fn range<'a>(
&'a self,
start: &[u8],
end: &[u8],
) -> impl Iterator<Item = Vec<u8>> + 'a
pub fn range<'a>( &'a self, start: &[u8], end: &[u8], ) -> impl Iterator<Item = Vec<u8>> + 'a
Iterate over keys in range [start, end)
Binary search for bounds, then sequential iteration.
Sourcepub fn stats(&self) -> DeferredIndexStats
pub fn stats(&self) -> DeferredIndexStats
Get statistics
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DeferredSortedIndex
impl !RefUnwindSafe for DeferredSortedIndex
impl Send for DeferredSortedIndex
impl Sync for DeferredSortedIndex
impl Unpin for DeferredSortedIndex
impl UnwindSafe for DeferredSortedIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more