Skip to content

Commit 49e977d

Browse files
committed
reader-map: Add threshold-based B-tree storage option
Because the vector is stored in sorted order, insertions during startup are O(n^2). We add optional B-tree storage, and we cut over to a B-tree at a hardcoded threshold of 10 values. Change-Id: Ifb161a77c23d7e9669791415f73aad605c9ff2e2 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7959 Tested-by: Buildkite CI Reviewed-by: Jason Brown <[email protected]>
1 parent 531a893 commit 49e977d

File tree

5 files changed

+286
-50
lines changed

5 files changed

+286
-50
lines changed

partial-map/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ where
504504
}
505505

506506
/// A trait that is required to keep the inner values in the correct order
507-
pub trait InsertionOrder<V>: Clone + Default {
507+
pub trait InsertionOrder<V>: Clone + fmt::Debug + Default {
508508
/// Compare two elements, like [`Ord::cmp`], but the comparison can be based on anything,
509509
/// not necessarily the same as `a.cmp(b)`.
510510
fn cmp(&self, a: &V, b: &V) -> std::cmp::Ordering;

reader-map/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,15 @@ where
460460
{
461461
Options::default().construct()
462462
}
463+
464+
#[cfg(test)]
465+
mod test {
466+
use super::*;
467+
468+
#[test]
469+
fn default_size() {
470+
// By ensuring this type is a ZST, we ensure that BTreeValue is a zero-cost wrapper
471+
// around the wrapped value.
472+
assert_eq!(std::mem::size_of::<DefaultInsertionOrder>(), 0);
473+
}
474+
}

reader-map/src/read.rs

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ where
167167
pub fn first<'rh, Q>(&'rh self, key: &'_ Q) -> Result<Option<ReadGuard<'rh, V>>>
168168
where
169169
K: Borrow<Q>,
170+
V: Ord,
170171
Q: Ord + Clone + Hash,
171172
{
172173
let vs = if let Some(vs) = self.get_raw(key.borrow())? {

reader-map/src/read/read_ref.rs

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ where
156156
pub fn first<'a, Q>(&'a self, key: &'_ Q) -> Option<&'a V>
157157
where
158158
K: Borrow<Q>,
159+
V: Ord,
159160
Q: Ord + Hash + ?Sized,
160161
{
161162
self.guard.data.get(key).and_then(|values| values.first())

0 commit comments

Comments
 (0)