perf: fix a perf regression

This commit is contained in:
Zixuan Chen 2023-08-07 20:14:01 +08:00
parent addadcdce5
commit 299f00d90f
4 changed files with 32 additions and 10 deletions

View file

@ -1,6 +1,5 @@
// use bench_utils::{get_automerge_actions, TextAction};
// use loro_internal::{EncodeMode, LoroCore, VersionVector};
// use rand::{rngs::StdRng, Rng, SeedableRng};
use bench_utils::{get_automerge_actions, TextAction};
use loro_internal::LoroDoc;
// #[allow(dead_code)]
// fn parallel() {
@ -62,5 +61,24 @@
// }
fn main() {
// real_time()
let actions = get_automerge_actions();
let loro = LoroDoc::default();
let loro_b = LoroDoc::default();
let text = loro.get_text("text");
let mut count = 0;
for TextAction { pos, ins, del } in actions.iter() {
{
let mut txn = loro.txn().unwrap();
text.delete(&mut txn, *pos, *del).unwrap();
text.insert(&mut txn, *pos, ins).unwrap();
}
loro_b
.import(&loro.export_from(&loro_b.oplog_vv()))
.unwrap();
count += 1;
if count % 1000 == 0 {
println!("{}", count);
}
}
}

View file

@ -1,3 +1,4 @@
use debug_log::debug_dbg;
use loro_common::IdSpanVector;
use rle::{rle_tree::UnsafeCursor, HasLength, Sliceable};
use smallvec::SmallVec;

View file

@ -1,3 +1,4 @@
use debug_log::debug_dbg;
use enum_dispatch::enum_dispatch;
use fxhash::{FxHashMap, FxHashSet};
use loro_common::{HasIdSpan, PeerID, ID};
@ -56,11 +57,13 @@ impl DiffCalculator {
after: &crate::VersionVector,
after_frontiers: Option<&Frontiers>,
) -> Vec<InternalContainerDiff> {
let include_before = self.last_vv.includes_vv(before);
let include_after = self.last_vv.includes_vv(after);
if self.has_all && (!include_after || !include_before) {
self.has_all = false;
self.last_vv = Default::default();
if self.has_all {
let include_before = self.last_vv.includes_vv(before);
let include_after = self.last_vv.includes_vv(after);
if !include_after || !include_before {
self.has_all = false;
self.last_vv = Default::default();
}
}
let affected_set = if !self.has_all {

View file

@ -208,7 +208,7 @@ impl LoroDoc {
let old_frontiers = oplog.frontiers().clone();
oplog.decode(bytes)?;
if !self.detached {
let mut diff = self.diff_calculator.lock().unwrap();
let mut diff = DiffCalculator::default();
let diff = diff.calc_diff_internal(
&oplog,
&old_vv,