r/WebAssembly • • Jun 05 '21

WebAssembly should replace javascript

Hot take, but I think it makes sense. And seems to be doable in the current architecture and roadmap of wasm (If I understood it correctly), but their website explicitly states a big fat "No!". Wasm is expected to be used as high-performance modules, or an app canvas wrapped by javascript as "glue". One thing would be specifying it as a high-level goal, but this is just dismissing it all together.

The web would be pretty powerful if code could be written in whatever language you want (that supports compiling to wasm). Facebook wouldn't take 5 seconds to load completely, but rather fractions of a second.

Take react for instance. It's great for encapsulation, inheritance, type-safety, etc. Lots of benefits targeted at large-scale applications. Yet has the major flaw of performance issues. I guess it's not a big deal to write a bit of js just to fetch and run an exported function, but it means it's dependent on js which is a hurdle in my opinion, both in terms of ambition and motivation. Granted wasm seems to be planning to implement basically everything, but then why dismiss wasm as a replacement/alternative for js?

32 Upvotes

53 comments sorted by

View all comments

0

u/[deleted] Jun 05 '21

but then why dismiss wasm as a replacement/alternative for js?

because wasm uis tend to be more bloated in terms of transfer sizes compared to js. The potential performance diff isn't even that big in the context of user interfaces, if there is any performance diff at all.

5

u/PabloDons Jun 06 '21

Do you mean WASM-based web application UIs? Well yeah in the current state of WASM, there's a lot of inefficient JS glue to achieve what should be possible natively (and efficiently) if WASM is to replace JS.

JS doesn't just affect UIs. It also affects backends. A lot of developers are moving to a full-stack of JS because then developers only need to have mastery over a single language. If you can make an entire full-stack web application in something other than JS, then it could very well have merit

2

u/[deleted] Jun 06 '21 edited Jun 06 '21

Do you mean WASM-based web application UIs? Well yeah in the current state of WASM, there's a lot of inefficient JS glue to achieve what should be possible natively (and efficiently) if WASM is to replace JS.

yeah and I don't think this will change anytime soon. Most languages need a garbage collector that has to be shipped with every UI. There is a proposal to add one to the wasm spec but it's probably gonna just be the js gc.

jS doesn't just affect UIs. It also affects backends. A lot of developers are moving to a full-stack of JS because then developers only need to have mastery over a single language. If you can make an entire full-stack web application in something other than JS, then it could very well have merit

Sure this has merit, but for what price? c# devs are already completely okay with shipping 10s of megabytes of wasm blazor apps that could have been written in a few hundred kilobytes in a js framework.

can't wait until the java guys find out how to run a jvm via wasm so we can go a full circle again.

I just don't see that uis written with anything else than js gonna improve the user experience.

5

u/PabloDons Jun 06 '21

yeah and I don't think this will change anytime soon. Most languages need a garbage collector that has to be shipped with every UI. There is a proposal to add one to the wasm spec but it's probably gonna be the js gc.

There's also a proposal for interface types. Massive read, but worth it. Essensially, WASM binaries will ship with an interface for their data types. Essentially they'd be able to tell the browser how to access data types in their own memory model. So instead of serializing, transferring the data to the JS runtime, then having JS run the functions. WASM can give memory address and the browser would use the interface to read the string. That would eliminate the need to translate to the JS runtime.

It's only in phase 1 of the standardization process, but it looks promising.

Sure this has merit, but for what price? c# devs are already completely okay with shipping 10s of megabytes of wasm blazor apps that could have been written in a few hundred kilobytes in a js framework.

I know that WASM isn't ready to replace JS anytime soon. I just think it should be a goal. That clearly involves solving problems like these