logoalt Hacker News

cedwsyesterday at 9:18 PM11 repliesview on HN

When is WASM finally going to be able to touch the DOM? It feels like that was the whole point of WASM and instead its become a monster of its own that barely has anything to do with web anymore. When can we finally kill JavaScript?


Replies

apatheticonionyesterday at 10:08 PM

Agreed. This and (sane) access to multi-threading. I want to be able to write a Rust application, compile to wasm and load it with

    <html>
    <body>
        <div id="root"></div>
        <script type="application/wasm" src="./main.wasm"></script>
    </body>
    </html>
Would be great for high performance web applications and for contexts like browser extensions where the memory usage and performance drain is real when multiplied over n open tabs. I'm not sure how code splitting would work in the wasm world, however.

v8 could be optimized to reduce its memory footprint if it detects that no JavaScript is running - or wasm-only applications could use an engine like wasmer and bypass v8 entirely.

Another factor is that web technologies are used to write desktop applications via Electron/similar. This is probably because desktop APIs are terrible and not portable. First class wasm support in the web would translate to more efficient desktop applications (Slack, VSCode, Discord, etc) and perhaps less hate towards memory heavy electron applications.

show 3 replies
dfabulichtoday at 6:56 AM

Basically never, because it would require re-standardizing the DOM with a lower-level API. That would take years, and no major browser implementor is interested in starting down that road. https://danfabulich.medium.com/webassembly-wont-get-direct-d...

Killing JavaScript was never the point of WASM. WASM is for CPU-intensive pure functions, like video decoding.

Some people wrongly thought that WASM was trying to kill JS, but nobody working on standardizing WASM in browsers believed in that goal.

show 2 replies
p_ltoday at 7:19 AM

GC was required part, because it was needed to allow interaction between DOM-side lifetimes and WASM-side lifetimes. You might still need a puny shim to essentially "declare" whatever form you want the DOM API to look like on WASM side (probably utilizing components and WIT in the future) but that shim won't have to do anything other than register the APIs because WASM will be able to take a reference to DOM object and vice versa instead of throwing a copy of data over the wall as it is now.

show 1 reply
vinkelhakeyesterday at 9:33 PM

You can write a WASM program today that touches the DOM, it just needs to go through the regular JS APIs. While there were some discussions early on about making custom APIs for WASM to access, that has long since been dropped - there are just too many downsides.

show 5 replies
DarkNova6yesterday at 9:30 PM

I am watching patiently from a distance to my hands on a well-designed frontend language but can't help to wonder... is it really _that_ inefficient to call a JS wrapper to touch the DOM?

Most code already is so horribly inefficient that I can't imagine this making a noticeable difference in most scenarios.

show 1 reply
namuolyesterday at 10:22 PM

> When can we finally kill JavaScript?

If you think JavaScript has problems I have bad news about the DOM…

show 1 reply
rtpgyesterday at 10:41 PM

One of the things that I think make this tricky is that if you have any DOM references you now have visibility into a GCable object.

Part of the web Javascript security model is that you cannot see into garbage collection. So if you have some WASM-y pointer to a DOM element, how do you handle that?

I think with GC in properly people might come at this problem again, but pre-GC WASM this sounds pretty intractable

pverheggenyesterday at 9:53 PM

Probably never. There's a pretty good recent thread on this topic:

https://news.ycombinator.com/item?id=44775801

jesse__yesterday at 11:11 PM

Hot take alert

> When is WASM finally going to be able to touch the DOM?

Coming from a web background, and having transitioned to games / realtime 3D applications...

Fuck the DOM dude. The idea that programming your UI via not one but TWO DSLs, and a scripting language, is utter madness. In principal, it might sound good (something something separation of concerns, or whatever-the-fuck), but in reality you always end up with this tightly coupled garbage fire split across a pile of different files and languages. This is not the way.

We need to build better native UI libraries that just open up a WebGL context and draw shit to that. DearIMGUI can probably already do like 85% of what modern webapps do.

Anyways .. /rant

show 4 replies
0x457yesterday at 11:10 PM

Probably only after Components and WIT are stabilized. No point of making it wihtout it IMO.

icaryesterday at 9:31 PM

I would bet on browsers being able to consume Typescript before WASM exposing any DOM API. That'd improve the Javascript situation a bit, at least.

show 1 reply