forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

encoding_refactored.rs115 lines, 3.6 KiBHistoryRawDownload
1use bench_utils::TextAction;
2use loro_internal::{cursor::PosType, loro::ExportMode, LoroDoc};
3use std::hint::black_box;
4
5fn main() {
6 log_size();
7 // bench_decode();
8 // bench_decode_updates();
9}
10
11#[allow(unused)]
12fn log_size() {
13 let actions = bench_utils::get_automerge_actions();
14 {
15 let loro = LoroDoc::default();
16 let text = loro.get_text("text");
17 let mut txn = loro.txn().unwrap();
18
19 for TextAction { pos, ins, del } in actions.iter() {
20 text.delete_with_txn(&mut txn, *pos, *del, PosType::Unicode)
21 .unwrap();
22 text.insert_with_txn(&mut txn, *pos, ins, PosType::Unicode)
23 .unwrap();
24 }
25 txn.commit().unwrap();
26 let snapshot = loro.export(ExportMode::Snapshot).unwrap();
27 let updates = loro.export(ExportMode::all_updates()).unwrap();
28 let json_updates = serde_json::to_string(
29 &loro
30 .export_json_updates(&Default::default(), &loro.oplog_vv(), true)
31 .unwrap(),
32 )
33 .unwrap();
34 println!("\n");
35 println!("Snapshot size={}", snapshot.len());
36 println!("Updates size={}", updates.len());
37 println!("Json Updates size={}", json_updates.len());
38 println!("\n");
39 loro.diagnose_size();
40 }
41 println!("\n");
42 println!("\n");
43 println!("\n");
44 {
45 println!("One Transaction Per Action");
46 let loro = LoroDoc::default();
47 let text = loro.get_text("text");
48
49 for TextAction { pos, ins, del } in actions.iter() {
50 let mut txn = loro.txn().unwrap();
51 text.delete_with_txn(&mut txn, *pos, *del, PosType::Unicode)
52 .unwrap();
53 text.insert_with_txn(&mut txn, *pos, ins, PosType::Unicode)
54 .unwrap();
55 txn.commit().unwrap();
56 }
57 let snapshot = loro.export(ExportMode::Snapshot).unwrap();
58 let updates = loro.export(ExportMode::all_updates()).unwrap();
59 println!("\n");
60 println!("Snapshot size={}", snapshot.len());
61 println!("Updates size={}", updates.len());
62 println!("\n");
63 loro.diagnose_size();
64 }
65}
66
67#[allow(unused)]
68fn bench_decode() {
69 println!("Bench decode");
70 let actions = bench_utils::get_automerge_actions();
71 {
72 let mut loro = LoroDoc::default();
73 let text = loro.get_text("text");
74 loro.start_auto_commit();
75
76 for _ in 0..10 {
77 for TextAction { pos, ins, del } in actions.iter() {
78 text.delete(*pos, *del, PosType::Unicode).unwrap();
79 text.insert(*pos, ins, PosType::Unicode).unwrap();
80 }
81 }
82 let snapshot = loro.export(ExportMode::Snapshot).unwrap();
83 // for _ in 0..100 {
84 // black_box(loro.export(ExportMode::Snapshot));
85 // }
86
87 for _ in 0..100 {
88 let loro = LoroDoc::new();
89 loro.import(black_box(&snapshot)).unwrap();
90 }
91 }
92}
93
94#[allow(unused)]
95fn bench_decode_updates() {
96 let actions = bench_utils::get_automerge_actions();
97 let loro = LoroDoc::default();
98 let text = loro.get_text("text");
99
100 #[allow(warnings)]
101 for TextAction { pos, ins, del } in actions.iter() {
102 let mut txn = loro.txn().unwrap();
103 text.delete_with_txn(&mut txn, *pos, *del, PosType::Unicode)
104 .unwrap();
105 text.insert_with_txn(&mut txn, *pos, ins, PosType::Unicode)
106 .unwrap();
107 txn.commit().unwrap();
108 }
109
110 let updates = loro.export(ExportMode::all_updates()).unwrap();
111 for _ in 0..10 {
112 let loro = LoroDoc::new();
113 loro.import(black_box(&updates)).unwrap();
114 }
115}