//! WASM memory of an authority through a long session: open a document, then //! apply `n` peer updates one by one, as DocsModel.refresh does. //! cargo run --release --example session_memory -- doc.bin 2000 use docs_native_host::Host; use serde_json::json; fn main() { let args: Vec = std::env::args().collect(); let bytes = std::fs::read(&args[1]).unwrap(); let n: usize = args.get(2).map(|v| v.parse().unwrap()).unwrap_or(2000); 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 }; let mut authority = open(11); let mut peer = open(12); let opened = authority.memory_bytes(); for i in 0..n { 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(); let mut e = vec![255]; e.extend(update); authority.call(&e).unwrap(); } 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); }