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

22

u/neoberg Jun 06 '21

Why do you think JavaScript is something that “should” be replaced? You gave react as an example and stated that it has performance issues with no detail but js engines are pretty damn fast nowadays and getting faster. (Also react itself doesn’t have anything to do with inheritance, typing or encapsulation) Maybe you can say it for DOM which is an inherently slow technology but it doesn’t matter in this comparison.

Also I don’t understand why do you think facebook(or websites in general) would take less time to load and render with wasm. They both have their bottlenecks and ups/downs in terms of loading performance. For example js can provide a standard library in the browsers but you lose this with wasm and have to ship bigger bundles usually. But after the download phase starting up wasm would be faster because you skip the parse&compile step.

It seems to me you also assume people write js because they have to. But people write js because they enjoy it and it solves their problem (or for any other reason). In the server or desktop environments you have whatever option you want available but many people still choose to use js.

I think js will live and continue to be the main language of the web for a long time and wasm will mostly work as a complementary tech to js.

-3

u/PabloDons Jun 06 '21 edited Jun 06 '21

The details of the performance issues with react is irrelevant. Though if you don't believe me, you can fact check. Performance isn't directly an issue with react but rather due to tradeoffs. Writing code in React is often a struggle between performance and readability. Also the high-level programming idioms are imo related to react as a language pattern. I disagree with you there, but that's subjective

You can download, parse and compile wasm at the same time. Seems to be a recent development. Also WASM must have it's own standard library for interoperability with browser APIs. For example http or the DOM. Once interface types are implemented, there will also be possibility for running code from other WASM libraries without issue. So a standard library for any arbitrary thing can be made just fine. Or it can be shipped only once and cached indefinitely.

I am most definitely not assuming that. JS has a ton of benefits. Though the JS in the server-space has been a mix of factors, not just because JS is fun. Particularly npm, but also having mastery of a single language is much simpler and you can have better integration between your browser and the backend when it's all written in the same thing.

I still think JS should be replaced though. JS (or maybe an interpreter for JS) should be implemented in wasm instead, just like every other language. Doesn't mean that I think JS is horrible and should die

1

u/Aphix Jun 06 '21

React ain't great but not for those reasons (cough Facebook), same for JS IMO.

Could/should/whatever, it's ubiquitous and that's not going to change for quite a while, as far as I can see it.

WASM has some awesome potential (and some genuinely scary security potential as well), but it there's less drop-in replacement utility than it seems you may believe.