We rewrote our Rust WASM parser in TypeScript and it got faster

zahlekhan 155 points 88 comments March 20, 2026
www.openui.com · View on Hacker News

Discussion Highlights (20 comments)

blundergoat

The real win here isn't TS over Rust, it's the O(N²) -> O(N) streaming fix via statement-level caching. That's a 3.3x improvement on its own, independent of language choice. The WASM boundary elimination is 2-4x, but the algorithmic fix is what actually matters for user-perceived latency during streaming. Title undersells the more interesting engineering imo.

dmix

That blog post design is very nice. I like the 'scrollspy' sidebar which highlights all visible headings. Claude tells me this is https://www.fumadocs.dev/

nine_k

"We rewrote this code from language L to language M , and the result is better!" No wonder: it was a chance to rectify everything that was tangled or crooked, avoid every known bad decision, and apply newly-invented better approaches. So this holds even for L = M . The speedup is not in the language, but in the rewriting and rethinking.

spankalee

I was wondering why I hadn't heard of Open UI doing anything with WASM. This new company chose a very confusing name that has been used by the Open UI W3C Community Group for over 5 years. https://open-ui.org/ Open UI is the standards group responsible for HTML having popovers, customizable select, invoker commands, and accordions. They're doing great work.

caderosche

What is the purpose of the Rust WASM parser? Didn't understand that easily from the article. Would love a better explanation.

evmar

By the way, I did a deeper dive on the problem of serializing objects across the Rust/JS boundary, noticed the approach used by serde wasn’t great for performance, and explored improving it here: https://neugierig.org/software/blog/2024/04/rust-wasm-to-js....

SCLeo

They should rewrite it in rust again to get another 3x performance increase /s

slowhadoken

Am I mistaken or isn’t TypeScript just Golang under the hood these days?

szmarczak

> Attempted Fix: Skip the JSON Round-Trip > We integrated serde-wasm-bindgen So you're reinventing JSON but binary? V8 JSON nowadays is highly optimized [1] and can process gigabytes per second [2], I doubt it is a bottleneck here. [1] https://v8.dev/blog/json-stringify [2] https://github.com/simdjson/simdjson

neuropacabra

This is very unusual statement :-D

nallana

Why not a shared buffer? Serializing into JSON on this hot path should be entirely avoidable

ivanjermakov

Good software is usually written on 2nd+ try.

joaohaas

God I hate AI writing. That final summary benchmark means nothing. It mentions 'baseline' value for the 'Full-stream total' for the rust implementation, and then says the `serde-wasm-bindgen` is '+9-29% slower', but it never gives us the baseline value, because clearly the only benchmark it did against the Rust codebase was the per-call one. Then it mentions: "End result: 2.2-4.6x faster per call and 2.6-3.3x lower total streaming cost." But the "2.6-3.3x" is by their own definition a comparison against the naive TS implementation. I really think the guy just prompted claude to "get this shit fast and then publish a blog post".

nssnsjsjsjs

Rewrite bias. Yoy want to also rewrite the Rust one in Rust for comparison.

rented_mule

Something not unlike this happened to me when moving some batch processing code from C++ to Python 1.4 (this was 1997). The batch started finishing about 10x faster. We refused to believe it at first and started looking to make sure the work was actually being done. It was. The port had been done in a weekend just to see if we could use Python in production. The C++ code had taken a few months to write. The port was pretty direct, function for function. It was even line for line where language and library differences didn't offer an easier way. A couple of us worked together for a day to find the reason for the speedup. Just looking at the code didn't give us any clues, so we started profiling both versions. We found out that the port had accidentally fixed a previously unknown bug in some code that built and compared cache keys. After identifying the small misbehaving function, we had to study the C++ code pretty hard to even understand what the problem was. I don't remember the exact nature of the bug, but I do remember thinking that particular type of bug would be hard to express in Python, and that's exactly why it was accidentally fixed. We immediately started moving the rest of our back end to Python. Most things were slower, but not by much because most of our back end was i/o bound. We soon found out that we could make algorithmic improvements so much more quickly, so a lot of the slowest things got a lot faster than they had ever been. And, most importantly, we (the software developers) got quite a bit faster.

slopinthebag

This article is obviously AI generated and besides being jarring to read, it makes me really doubt its validity. You can get substantially faster parsing versus `JSON.parse()` by parsing structured binary data, and it's also faster to pass a byte array compared to a JSON string from wasm to the browser. My guess is not only this article was AI generated, but also their benchmarks, and perhaps the implementation as well.

jeremyjh

> The openui-lang parser converts a custom DSL emitted by an LLM into a React component tree. > converts internal AST into the public OutputNode format consumed by the React renderer Why not just have the LLM emit the JSON for OutputNode ? Why is a custom "language" and parser needed at all? And yes, there is a cost for marshaling data, so you should avoid doing it where possible, and do it in large chunks when its not possible to avoid. This is not an unknown phenomenon.

envguard

The WASM story is interesting from a security angle too. WASM modules inheriting the host's memory model means any parsing bugs that trigger buffer overreads in the Rust code could surface in ways that are harder to audit at the JS boundary. Moving to native TS at least keeps the attack surface in one runtime, even if the theoretical memory safety guarantees go down.

marcosdumay

It would be great if people stopped dismissing the problem that WASM not being a first-class runtime for the web causes.

kennykartman

I dream of the day in which there is no need to pass by JS and Wasm can do all the job by itself. Meanwhile, we are stuck.

Semantic search powered by Rivestack pgvector
3,471 stories · 32,344 chunks indexed