Skip to content

Commit

Permalink
Changed DT-CRDT to use faster btree impl. Changed run-on-old to merge…
Browse files Browse the repository at this point in the history
… delete operations. Added stats tracking. Perf increased. Disabled positional updates & OT code in DT-CRDT - see dt-crdt-fully-working branch for older version of the code.
  • Loading branch information
josephg committed Jul 19, 2024
1 parent 5d633a9 commit 22f68b1
Show file tree
Hide file tree
Showing 30 changed files with 6,903 additions and 1,843 deletions.
1 change: 1 addition & 0 deletions crates/diamond-types-crdt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ json_minimal = "0.1.3"
memusage = []
inlinerope = []
serde = ["dep:serde", "smallvec/serde", "smartstring/serde"]
stats = []

[lib]
bench = false
Expand Down
4 changes: 2 additions & 2 deletions crates/diamond-types-crdt/src/crdtspan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use content_tree::ContentLength;
use diamond_core_old::CRDTId;
use rle::{HasLength, MergableSpan, SplitableSpanHelpers};

use content_tree::ContentLength;
use rle::Searchable;

#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
Expand All @@ -20,7 +20,7 @@ impl Searchable for CRDTSpan {
if self.loc.agent == loc.agent
&& loc.seq >= self.loc.seq
&& loc.seq < self.loc.seq + self.len {
Some((loc.seq - self.loc.seq) as usize)
Some(loc.seq - self.loc.seq)
} else { None }
}

Expand Down
4 changes: 4 additions & 0 deletions crates/diamond-types-crdt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ mod unicount;
mod crdtspan;
mod rangeextra;
mod dtrange;
mod ost;

#[cfg(feature = "stats")]
pub use list::stats::take_stats;

// TODO: Move this somewhere else.
pub fn root_id() -> RemoteId {
Expand Down
54 changes: 29 additions & 25 deletions crates/diamond-types-crdt/src/list/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use jumprope::JumpRope;
use crate::list::{ListCRDT, ROOT_LV};
use rle::HasLength;
use smallvec::{SmallVec, smallvec};
use crate::ost::content_tree::Content;

/// This file contains debugging assertions to validate the document's internal state.
///
Expand All @@ -21,36 +22,35 @@ impl ListCRDT {
pub fn check(&self, deep: bool) {
// self.index.check();

self.range_tree.dbg_check();

if let Some(text) = self.text_content.as_ref() {
assert_eq!(self.range_tree.content_len() as usize, text.len_chars());
assert_eq!(self.range_tree.total_len() as usize, text.len_chars());

let num_deleted_items = self.deletes.iter().fold(0, |x, y| x + y.len());
if let Some(del_content) = self.deleted_content.as_ref() {
assert_eq!(del_content.chars().count(), num_deleted_items);
}
}

let mut cursor = self.range_tree.cursor_at_start();
loop {
// The call to cursor.next() places the cursor at the next item before returning.
let this_cursor = cursor.clone();

if let Some(e) = cursor.next() { // Iterating manually for the borrow checker.
// Each item's ID should come after its origin left and right
assert!(e.origin_left == ROOT_LV || e.lv > e.origin_left);
assert!(e.origin_right == ROOT_LV || e.lv > e.origin_right);
assert_ne!(e.len, 0);

if deep {
// Also check that the origin left appears before this entry, and origin right
// appears after it.
let left = self.get_cursor_after(e.origin_left, true);
assert!(left <= this_cursor);

let right = self.get_cursor_before(e.origin_right);
assert!(this_cursor < right);
}
} else { break; }
for e in self.range_tree.iter() {
// Each item's ID should come after its origin left and right
assert!(e.origin_left == ROOT_LV || e.lv > e.origin_left);
if e.origin_left != ROOT_LV || e.origin_right != ROOT_LV {
assert_ne!(e.origin_left, e.origin_right);
}
assert!(e.origin_right == ROOT_LV || e.lv > e.origin_right);
assert_ne!(e.len, 0);

// if deep {
// // Also check that the origin left appears before this entry, and origin right
// // appears after it.
// let left = self.get_cursor_after(e.origin_left, true);
// assert!(left <= this_cursor);
//
// let right = self.get_cursor_before(e.origin_right);
// assert!(this_cursor < right);
// }
}

if deep {
Expand All @@ -61,9 +61,13 @@ impl ListCRDT {

fn check_index(&self) {
// Go through each entry in the range tree and make sure we can find it using the index.
for entry in self.range_tree.raw_iter() {
let marker = self.marker_at(entry.lv);
unsafe { marker.as_ref() }.find(entry.lv).unwrap();
for (leaf_idx, items) in self.range_tree.iter_leaves() {
for e in items {
if !e.exists() { break; }

let marker = self.marker_at(e.lv);
assert_eq!(marker.0, leaf_idx);
}
}
}

Expand Down
Loading

0 comments on commit 22f68b1

Please sign in to comment.