Rust & WebAssembly · Patterns
Zero-Copy Data Exchange
Avoiding redundant copies across the JS/WASM boundary.
1 min readPublished Updated
- wasm
- memory
Copying large typed arrays between JS and WASM linear memory is often the real bottleneck, not the computation itself.
rust
#[wasm_bindgen]
pub fn process(data: &[f32]) -> Vec<f32> {
data.iter().map(|v| v * 2.0).collect()
}Views over shared memory (Float32Array backed by the WASM memory buffer) avoid redundant copies.