bench: sync 2000 times

This commit is contained in:
leeeon233 2023-02-20 20:02:38 +08:00
parent 379c3201f5
commit 037d17cd08
2 changed files with 18 additions and 17 deletions

View file

@ -5,6 +5,7 @@ mod sync {
use super::*;
use bench_utils::{get_automerge_actions, TextAction};
use loro_internal::container::registry::ContainerWrapper;
use loro_internal::log_store::EncodeConfig;
use loro_internal::LoroCore;
pub fn b4(c: &mut Criterion) {
@ -14,24 +15,23 @@ mod sync {
b.bench_function("update", |b| {
let mut c1 = LoroCore::new(Default::default(), Some(0));
let mut c2 = LoroCore::new(Default::default(), Some(1));
let t1 = c1.get_text("text");
let t2 = c2.get_text("text");
let mut t1 = c1.get_text("text");
let mut t2 = c2.get_text("text");
b.iter(|| {
for (i, action) in actions.iter().enumerate() {
if i > 2000 {
break;
}
let TextAction { pos, ins, del } = action;
if i % 2 == 0 {
t1.with_container(|text| {
text.delete(&c1, *pos, *del);
text.insert(&c1, *pos, ins);
});
let update = c1.encode_from(c2.vv_cloned());
t1.delete(&c1, *pos, *del).unwrap();
t1.insert(&c1, *pos, ins).unwrap();
let update = c1.encode_with_cfg(EncodeConfig::update(c2.vv_cloned()));
c2.decode(&update).unwrap();
} else {
t2.with_container(|text| {
text.delete(&c2, *pos, *del);
text.insert(&c2, *pos, ins);
});
let update = c2.encode_from(c1.vv_cloned());
t2.delete(&c2, *pos, *del).unwrap();
t2.insert(&c2, *pos, ins).unwrap();
let update = c2.encode_with_cfg(EncodeConfig::update(c1.vv_cloned()));
c1.decode(&update).unwrap();
}
}
@ -44,20 +44,23 @@ mod sync {
let t2 = c2.get_text("text");
b.iter(|| {
for (i, action) in actions.iter().enumerate() {
if i > 2000 {
break;
}
let TextAction { pos, ins, del } = action;
if i % 2 == 0 {
t1.with_container(|text| {
text.delete(&c1, *pos, *del);
text.insert(&c1, *pos, ins);
});
let update = c1.encode_from(c2.vv_cloned());
let update = c1.encode_with_cfg(EncodeConfig::rle_update(c2.vv_cloned()));
c2.decode(&update).unwrap();
} else {
t2.with_container(|text| {
text.delete(&c2, *pos, *del);
text.insert(&c2, *pos, ins);
});
let update = c2.encode_from(c1.vv_cloned());
let update = c2.encode_with_cfg(EncodeConfig::rle_update(c1.vv_cloned()));
c1.decode(&update).unwrap();
}
}

View file

@ -328,7 +328,6 @@ pub(super) fn decode_snapshot(
// calc vv
let vv = calc_vv(&change_encodings, &ops, &clients, &idx_to_container_type);
// println!("remote vv {:?} self vv {:?}", vv, &store.vv);
let can_load = match vv.partial_cmp(&store.vv) {
Some(ord) => match ord {
std::cmp::Ordering::Less => {
@ -350,7 +349,7 @@ pub(super) fn decode_snapshot(
let mut deps_iter = deps.into_iter();
let mut idx_to_container_idx = FxHashMap::default();
// the container_idx need to be calculated first
// the container_idx needs to be calculated first
// because the op needs the corresponding container (in new or old store)
let new_loro = LoroCore::default();
let mut new_store = new_loro.log_store.try_write().unwrap();
@ -501,7 +500,6 @@ pub(super) fn decode_snapshot(
}
if can_load {
// println!("can load");
let mut import_context = load_snapshot(
store,
hierarchy,