oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1//! WASM memory of an authority through a long session: open a document, then
2//! apply `n` peer updates one by one, as DocsModel.refresh does.
3//! cargo run --release --example session_memory -- doc.bin 2000
4use docs_native_host::Host;
5use serde_json::json;
6fn main() {
7 let args: Vec<String> = std::env::args().collect();
8 let bytes = std::fs::read(&args[1]).unwrap();
9 let n: usize = args.get(2).map(|v| v.parse().unwrap()).unwrap_or(2000);
10 let open = |client: u64| { let mut h = Host::new().unwrap(); h.call(&serde_json::to_vec(&json!({"op":"open","guid":"m","client":client})).unwrap()).unwrap(); let mut e = vec![255]; e.extend(&bytes); h.call(&e).unwrap(); h };
11 let mut authority = open(11);
12 let mut peer = open(12);
13 let opened = authority.memory_bytes();
14 for i in 0..n {
15 let update = peer.call(&serde_json::to_vec(&json!({"op":"display_edit","at":5 + (i % 50),"length":0,"text":"remote typing "})).unwrap()).unwrap().to_vec();
16 let mut e = vec![255]; e.extend(update); authority.call(&e).unwrap();
17 }
18 println!("opened {:.1} MiB, after {n} peer updates {:.1} MiB (doc {} KB)", opened as f64 / 1048576.0, authority.memory_bytes() as f64 / 1048576.0, bytes.len() / 1024);
19}
20