loro/crates/loro-internal/examples/pending.rs
Zixuan Chen 5cac1ed092
Refactor: make changes mergeable (#146)
- Allow changes to be merged when possible. This makes realtime collaboration more efficient with Loro.
- Refactor the code to make modifications of changes in oplog in one place
- Optimize the diff calculation so that it doesn't have to go back to the beginning of the change.

Note: we still keep the invariants that dependency pointers in Loro always point to the last op in a change
2023-11-03 21:40:34 +08:00

30 lines
1 KiB
Rust

use bench_utils::TextAction;
use loro_internal::{LoroDoc, VersionVector};
pub fn main() {
let loro = LoroDoc::default();
let mut latest_vv = VersionVector::default();
let mut updates = vec![];
let actions = bench_utils::get_automerge_actions();
let action_length = actions.len();
let text = loro.get_text("text");
for (_, chunks) in actions.chunks(action_length / 10).enumerate() {
for TextAction { pos, ins, del } in chunks {
let mut txn = loro.txn().unwrap();
text.delete(&mut txn, *pos, *del).unwrap();
text.insert(&mut txn, *pos, ins).unwrap();
updates.push(loro.export_from(&latest_vv));
latest_vv = loro.oplog_vv();
}
}
println!("done encoding");
updates.reverse();
let start = std::time::Instant::now();
let mut store2 = LoroDoc::default();
store2.detach();
for update in updates.iter() {
store2.import(update).unwrap();
}
println!("Elapsed {}", start.elapsed().as_millis());
}