We replaced our Rust/WASM parser with TypeScript and it got 3x faster

403 points 1glasspaani 112 comments

We build a streaming parser that converts LLM output into React components, running on every chunk. Originally wrote it in Rust/WASM. Profiling showed the parsing was never the bottleneck. The cost was entirely in the WASM-JS boundary: copying strings in, serializing to JSON, copying back out, V8 deserializing again.

Tried serde-wasm-bindgen to return JS objects directly. 30% slower. Hundreds of tiny boundary crossings are worse than one JSON string that V8's native JSON.parse handles in a single pass.

Full writeup with benchmarks in link

Anyone else hit a case where WASM made things slower than expected?