42

Increasing the performance of WebAssembly Text Format parser by 350%

So it went from parsing at 25MiB/s to 115MiB/s. I feel like 115MiB/s is very slow for a Rust program, I wonder what it's up to that makes it so slow now. No diss to the author, good speedup, and it might be good enough for them.

2 hours agowritebetterc

115 MiB/s is something like 20 to 30 cycles per byte on a laptop, 50 on a desktop. That’s definitely quite slow as far as a CPU’s capacity to ingest bytes, but unfortunately about as fast as it gets for scalar (machine) code that does meaningful work per byte. There may be another factor of 2 or 3 somewhere, or there may not be. If you want to go meaningfully faster, as in at least the speed of your disk[1], you need to stop doing work per byte and start vectorizing. For parsers, that is possible but hard.

[1] https://www.youtube.com/watch?v=p6X8BGSrR9w

an hour agomananaysiempre

"for Rust program"?

Isnt it more about the grammar than the prog lang?

2 hours agohigh_na_euv

The grammar matters also, of course. A pure Python program is going to be much slower than the equivalent Rust program, just because CPython is so slow.

I don't know if this does semantic analysis of the program as well.

an hour agowritebetterc

It’s funny how there is continuous reinvention of parsing approaches.

Why isn’t there already some parser generator with vector instructions, pgo, low stack usage. Just endless rewrites of recursive descent with caching optimizations sprinkled when needed.

2 hours agovjerancrnjak

Hardware also changes across time, so while something that was initially fast, people with new hardware tries it, finds it now so fast for them, then create their own "fast X". Fast forward 10 more years, someone with new hardware finds that, "huh why isn't it using extension Y" and now we have three libraries all called "Fast X".

2 hours agoembedding-shape

I'd say because parsing is very specific kind of work heavily dependent on the grammar you're dealing with

2 hours agohigh_na_euv

There are good parser generators, but potentially not as Rust libraries.

2 hours agomgaunard
[deleted]
5 days ago
[deleted]
2 hours ago

Anyone using WebAssembly yet? HTML, CSS, JavaScript - all there.

Just about nobody uses WebAssembly. It first appeared almost ten years ago. This is snail-speed evolution at best.

3 hours agoshevy-java

Sure, here's a Rust/WASM procedural skybox generator I threw together the other day, and is much, much faster at 16k renders then Javascript. https://tkte.ch/night-sky/

4 minutes agoTkTech

People use wasm for things that need wasm. My use case is my cross-platform game engine, because running both natively and in the browser was a priority for me. It is a wonderful tool and it is a truly magical feeling to see my native games running in the browser. But 99% of web developers are developing ordinary websites, so they don't need it. That's not an indictment of wasm.

3 hours agoanonymous908213

> Anyone using WebAssembly yet?

Yes, tons. Obviously not all, but large parts of these are WASM: https://itch.io/games/platform-web

Tools like Figma are only performant because of WASM.

2 hours agoembedding-shape

I use a wasm xxhash implementation that is 40x faster than the fastest JavaScript version I can find. Drop in replacement. Call overhead is minimal, could be better with stringref if that ever gets available. Also some other audio analysis stuff in wasm I've been using is 400x faster than the JavaScript implementation but admittedly I just went straight to wasm rather than try to optimize the js in that case.

an hour agoadzm

You have the wrong understanding about wasm. It's absolutely not supposed to be replacing HTML, CSS or JS.

And yes wasm is used wildly. On the web for expensive computation (Google earth, figma, autocad, unity games) or server side for portability and sandboxing (Cloudflare workers, fastly, …)

2 hours agomiki_oomiri

It is definitely meant to replace JS in some applications. It isn't quite there yet for normal web pages but it will be eventually. There are a few front-end web frameworks written in Rust that use WASM.

The whole "it's not meant to replace JS" thing was just to reduce pushback from JS devs.

30 minutes agoIshKebab

I'm writing a point and click adventure game, and for that I've built a dialogue editor that uses a local text-to-speech model to turn speech into audio that runs in WASM (or WebGPU if it's available).

From what I can tell WASM is mostly being used to run big libraries from other languages in web apps. That's not a particularly common thing to need, so it's not commonly used. That doesn't mean it's moving too slowly.

an hour agoonion2k

WebAssembly is a virtual ISA, not a replacement for HTML and CSS. It was also never meant to kill Javascript (which is actually a pretty nice language if you stick to the 'good parts' via Typescript and linting), but at most as an alternative or complement to JS, and as that WASM works really well.

an hour agoflohofwoe

wasm isn't meant to supersede html/css/js (unfortunately) and it's regularly used for high performance applications in the browser, web-based cad software, figma, youtube (i think they use wasm for codec fallback when support is spotty) etc

there is also games, stuff to do with video (ffmpeg built for wasm), ml applications (mlc), in fact it's currently impossible to use wasm w/o js to load the wasm binary

as a result, the web stack is a bit upside down now, w/o the seemingly "low level" and "high performance" parts over the slow bits (javascript)

2 hours agotaminka

I saw a few web apps that use Rust crates for physics. I guess they must be using wasm?

3 hours agodemaga

Figma