Writing Rust→Wasm? Treat it like systems work, not magic. Practical notes: https://notes.brooklynzelenka.com/Blog/Notes-on-Writing-Wasm My take: Wasm buys CPU isolation and predictable perf. Everything else—size, ABI, memory—costs time unless you plan for it.
Size & build: set panic = "abort", use wee_alloc or trim std, strip symbols, run wasm-opt -Oz. Use console_error_panic_hook in dev only. Toolchain: wasm-bindgen/wasm-pack for JS glue, wasm-opt/binaryen to shrink the .wasm.
Boundary costs are the real tax. JS↔Wasm calls, strings, closures: expensive. Batch calls, move hot loops into Rust, transfer bulk via memory + Uint8Array, avoid many small allocations or Closure::wrap leaks. Measure call/serialization times, not just CPU.
Takeaway: ship with a small, measured scope — put deterministic, CPU-heavy work in Wasm; keep orchestration in JS. Rule: don’t guess where to move code—profile, move the hot path, then optimize for size and boundary overhead. What’s your current Wasm bottleneck?
Top comments (0)