Remix.run Logo
peutetre 10 months ago

Here's a web framework in Rust: https://www.leptos.dev/

Here's Scheme in wasm calling JavaScript functions and DOM methods: https://spritely.institute/news/building-interactive-web-pag...

As time goes on WebAssembly will keep displacing JavaScript. We've entered the era of Zombie JavaScript.

esperent 10 months ago | parent | next [-]

I scanned the docs but don't have time to deep dive, and I couldn't see: how does this access the DOM? Does it call JS DOM API functions from rust? And what's the performance like for doing that?

rendaw 10 months ago | parent [-]

Not specific to leptos. My understanding is very rough, but rust's wasm-bindgen generates a javascript translation layer for the wasm. (Roughly) Javascript objects are stored in a lookup table and rust gets the handle (a number). Rust makes calls with that handle, which get translated back into javascript calls using the actual object. Similarly (I think) proxy objects are created for rust objects so javascript can call rust.

I was benchmarking some dom manipulation code and saw large GC pauses corresponding to the number of `element.classList` accesses I was doing from rust. I think the answer is that performance isn't great (compared to if browsers provided a wasm-native api that didn't have to go through javascript), but if you're doing a lot of calculation in rust or are writing a typically small UI it's not a significant cost... may be more important for graphics and visualization work.

wiseowise 10 months ago | parent | prev [-]

> As time goes on WebAssembly will keep displacing JavaScript. We've entered the era of Zombie JavaScript.

Just like Java has been dead for 20 years, now it is JS turn.

Delusional.

peutetre 10 months ago | parent [-]

Well, JavaScript displaced by Java as it goes: https://web.dev/case-studies/google-sheets-wasmgc

That's the thing about WebAssembly. It supports any language that compiles to it.

Like an old, worn-out horse, JavaScript will be taken to the knackery and reduced to glue. And then not even the glue will be needed anymore.