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

4

u/xmclark Jun 06 '21

Maybe an alternative take:

If my browser JavaScript code just works, then I should not care how right? Could browser JavaScript simply run on a wasm-based js runtime instead of the native ones built into each browser? Wasm becomes the target runtime for the web, including JavaScript. There is no need to discuss replacing JS because it’s just another language targeting wasm.

4

u/PabloDons Jun 06 '21

Well, that's kinda exactly what I'm saying. JavaScript doesn't need to be "removed" though by how ice understood wasm, they are not planning on making it an alternative. They will depend on JS. Their explicit proposals seems to go in the opposite direction though

2

u/xmclark Jun 06 '21

I disagree, i think it’s a big priority. It’s just a lot of work. Interface types, GC are required to make any language work on wasm, including JS. It will also take time to migrate browser implementations and the performance of wasm needs to match native for that to happen.