Breaking the WASM/JS communication performance barrier
9 months ago
- #wasm
- #web-development
- #performance
- Sledgehammer bindgen provides faster Rust batched bindings for JS code.
- wasm-bindgen is more general, allowing returning values and handling various types; better for most users.
- Sledgehammer is designed for web frameworks needing low-level, fast DOM access.
- Sledgehammer can be used alongside wasm-bindgen.
- String decoding is expensive; wasm-bindgen calls TextDecoder.decode per string, while Sledgehammer calls it once per batch.
- For small strings, decoding in JavaScript is faster to avoid TextDecoder.decode overhead.
- Benchmark link provided for performance comparison.
- Caching strings in JavaScript avoids repeated decoding.
- Static strings in Sledgehammer are hashed by pointer, not value.
- Operations in Sledgehammer are encoded as byte sequences, packed into arrays.
- Operations are batched in fours as u32, optimizing read costs.
- Benchmark link provided for operation encoding efficiency.