Skip to content

Commit

Permalink
chore: refine err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Nov 8, 2023
1 parent 9b18ff9 commit 116190c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
64 changes: 35 additions & 29 deletions crates/loro-internal/examples/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
use std::time::Instant;

use bench_utils::TextAction;
use loro_internal::LoroDoc;

fn main() {
let actions = bench_utils::get_automerge_actions();

// let loro = LoroDoc::default();
// let loro_b = LoroDoc::default();
// let text = loro.get_text("text");
// let mut i = 0;
// let start = Instant::now();
// 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();
// i += 1;
// if i == 30000 {
// break;
// }
// }

// println!("{}ms", start.elapsed().as_millis());

let loro = LoroDoc::default();
let loro_b = LoroDoc::default();
let text = loro.get_text("text");
let mut i = 0;
let start = Instant::now();

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();
i += 1;
if i == 30000 {
break;
}
let mut txn = loro.txn().unwrap();
text.delete(&mut txn, *pos, *del).unwrap();
text.insert(&mut txn, *pos, ins).unwrap();
txn.commit().unwrap();
}

println!("{}ms", start.elapsed().as_millis());

// let loro = LoroDoc::default();
// let text = loro.get_text("text");

// 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();
// txn.commit().unwrap();
// }
let snapshot = loro.export_snapshot();
let output = miniz_oxide::deflate::compress_to_vec(&snapshot, 6);
println!(
"snapshot size {} after compression {}",
snapshot.len(),
output.len()
);

// {
// // Delta encoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ impl RichtextState {
"pos: {}, len: {}, self.len(): {}",
pos,
len,
&self.to_string()
&self.len_entity(),
);
// PERF: may use cache to speed up
self.cursor_cache.invalidate();
Expand Down

0 comments on commit 116190c

Please sign in to comment.