But to answer your question, yes you can use Rust and Go practically in the browser. It just isn’t all that helpful except in narrow circumstances.
But to answer your question, yes you can use Rust and Go practically in the browser. It just isn’t all that helpful except in narrow circumstances.
The difference with Rust and Go is they have better synchronization capabilities - where JavaScript largely forces you to clone data between threads.
So while you may still be messaging worker threads in Rust/Go - threads share memory which is fast and you have access to things like atomics and mutexes.
We can use Rust in the browser today with WASM and it's super cool - but without something like WASI, extensive thunking through JavaScript is required, plus there are issues with threading.
I hope that one day we can initialize a wasm module via a script tag with the browser offering a wasi interface
`<script src="module.wasm" type="application/wasi">`
And that browsers allow for threading without the restrictive security headers we have today
https://github.com/WebAssembly/threads/blob/main/proposals/t...
But that’s not going to help when accessing the DOM.
Is there a proposal(s) covering DOM access?
I remember interface types were a thing a few years back. If you have access to a dom object (I assume by pointer?) and it is removed/GC'd - would the wasm module have a null pointer?
Isn't that what SharedArrayBuffer is for (avoiding)?
Again, there’s very few actual uses for wasm. The main one is when you have a preexisting library in a different language, other than that you don’t gain any real functionality from using it.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
In the past I have used a SharedArrayBuffer to store a custom Graph implementation sent between threads. I stored the adjacency list in the SAB with the rest of the data being stored as a plain object and cloned/sent via postMessage between threads.
This worked but is extremely janky, required an unsafe custom data structure, manual/unsafe memory page management, was difficult to read/review and the performance was lacklustre because half of the data structure was plain JS objects that needed to be serialized and cloned anyway.
Simply, JavaScript sucks for multithreading and it would be great to have the ability to write high performance, multithreaded, complex web applications in a language designed with parallelism in mind - like Rust or Go.
While wasm _today_ cannot offer that (at least not practically) - there is certainly a use case for replacing JavaScript in that context and I hope that it does.
JS will still be useful for basic applications that just need a little scripting
I must question whether the problem of random sites wanting to spin up a whole ton of cores that consume arbitrary amounts of compute and memory really needs to be solved.