this post was submitted on 07 Aug 2023
86 points (98.9% liked)

Programming

16975 readers
1288 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

I've been wondering about this for a while and haven't really found a great answer for it. From what I understand, WASM is:

  • Faster than JavaScript

  • Has a smaller file size

  • Can be compiled to from pretty much any programming language

  • Can be used outside of the browser easier thanks to WASI

So why aren't most websites starting to try replacing (most) JS with WASM now that it's supported by every major browser? The most compelling argument I heard is that WASM can't manipulate the DOM and a lot of people don't want to deal with gluing JS code to it, but aside from that, is there something I'm missing?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 12 points 1 year ago* (last edited 1 year ago) (1 children)

I’m genuinely confused by these responses. It’s as if most didn’t actually look into what WASM was besides a cursory glance and then answered right away.

First off WASM is (relatively) new. It’s at 1.0 which iirc is basically an MVP product. It will take years for all browsers to integrate it appropriately.

Why choose WASM over JS? You probably wouldn’t right now unless you wanted to help pioneer the technology. Again it’s fairly new and probably not expected to be used in professional environments yet.

As for the benefits, it’s mostly the speed of code execution. Yes JavaScript is fast and robust enough for current web apps. No it is nowhere near as fast as native code.

Think about PC games. When people need performance, JS is definitely not the first option or even one of them in most cases. You want a language closer to the metal which is why compiled languages like C++ are often used.

All that said, if it was in a mature phase and did run faster than JS, why would you care? Well with native compiled code, you could run some hefty programs from a browser with the speed of native code.

That potentially means running more intensive applications like games and photo editors completely on a website. You could bypass the need to download software. You would visit the website, the WASM code would be sent over and used in the browser to run the application.

You can also interact directly with JavaScript via a WASM and call WASM functions within JavaScript so it’s pretty connected.

Overall it’s a fairly new technology that when matured could mean a major change for how the web works. It will likely be a long time until we see it capable of being used professionally and even longer before we see widespread use.

[–] [email protected] 3 points 1 year ago

Most games, image processing libraries and other compute demanding libraries already use WASM in the browser. Have been for quite some time. It's already widely used in every case where it provides a substantial benefit.

But writing for GUI, which is what 99% of JS is used for, WASM provides little benefit. The speed bottleneck is mostly in DOM manipulation. And every web GUI framework uses 200 npm packages with something like webpack. Getting that to somehow work with your WASM code would be a nightmare if it's even feasible.