Compile yrs 0.28 to wasm32-wasip1 and run it in Go with wazero to compact Yjs update logs and extract ProseMirror JSON and plain text. Fixtures come from real Yjs, and y-prosemirror's output is the oracle. - Output matches y-prosemirror on every fixture; Yjs loads yrs snapshots - Snapshot + 200 updates compacts in 0.6-47 ms; WebAssembly costs at most 2x native - merge_updates is quadratic, so the server must compact incrementally Results and design rules are recorded in docs/adr/0003-yrs-wasm-wazero.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
924 B
Rust
24 lines
924 B
Rust
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//! Times the same operations natively, to measure what WebAssembly costs.
|
|
//! cargo run --release --example native -- ../fixtures/data/medium.updates
|
|
|
|
use std::time::Instant;
|
|
|
|
use docwell_yrs::{dw_compact, dw_to_json};
|
|
|
|
fn main() {
|
|
for path in std::env::args().skip(1) {
|
|
let log = std::fs::read(&path).unwrap();
|
|
let t = Instant::now();
|
|
let n = unsafe { dw_compact(log.as_ptr(), log.len() as u32) };
|
|
let compact = t.elapsed();
|
|
let snap = unsafe { std::slice::from_raw_parts(docwell_yrs::dw_out_ptr(), n as usize) }.to_vec();
|
|
let mut framed = (snap.len() as u32).to_le_bytes().to_vec();
|
|
framed.extend_from_slice(&snap);
|
|
let t = Instant::now();
|
|
unsafe { dw_to_json(framed.as_ptr(), framed.len() as u32) };
|
|
println!("{path}: compact {:?}, json from snapshot {:?}", compact, t.elapsed());
|
|
}
|
|
}
|