1

What’s Wrong with Web Assembly?

 3 years ago
source link: https://blog.bitsrc.io/whats-wrong-with-web-assembly-3b9abb671ec2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What’s Wrong with Web Assembly?

Does WASM have any future in web development?

Image for post
Image for post
Image by mohamed Hassan from Pixabay

Modern browsers are capable of so much more than rendering a web page. That’s one of the reasons why WebAssembly was born. In an attempt to take the performance of heavy-duty tasks to the next level, a bridge between JavaScript and machine code was created: WebAssembly.

In theory, this new tech would allow anyone to write machine code to run inside a virtual and safe sandbox in the browser. And even better, WASM (WebAssembly’s abbreviation) was designed as a compilation target for other languages, allowing server-side code (such as C or C++ code) to be compiled into it and executed inside the browser.

Its potential and its promise were huge. So what went wrong? Why isn’t everyone using WASM after 3 years of being released?

Let’s try to answer those questions.

What’s the point of WASM?

WASM was designed to provide highly optimized computation on the web, as well as the ability to break the monopoly that JavaScript currently holds on this environment.

It was not meant to be a new language for developers to actively write on. Instead, it was designed to be a compilation target that would allow a C developer to compile their code and run it on a browser.

Why would this be of any use? I hear you asking…

While JavaScript is a great language, it was not designed with performance in mind. And if you do allow other languages that bring that benefit to the table to be used alongside JS, you’d be able to reap the benefits of both worlds. But how do you allow for that? Through a compatible bridge known as WASM.

What are the use cases the creators had in mind then?

WASM wasn’t meant to optimize your website, it was meant to take browsers (and server-side runtimes such as Node.js) to the next level when performing tasks such as:

  • Video editing
  • Game development
  • AR / VR live applications
  • Music editing and streaming
  • Platform emulation
  • Encryption
  • Image recognition
  • And a lot more heavy-duty tasks.

Anything that would require a lot of coding and a lot of performance tweaking would be a perfect use case for WASM.

Who’s actually using it and what are they using it for?

For an open-source list of projects using WASM, you can visit this community made site.

However, if you’re not feeling like opening another tab, here are some of the most notorious names from that list:

  • Tensorflow.js. That’s right, Tensorflow, one of the main libraries that brought AI and ML to JS developers added WASM backend support a while ago and have been working on implementing more and more models ever since. The benefit? They saw an average of 10x improvement in the performance of their models over the plain JS version.
  • Unity. Another big name. One of the major game development engines out there, it is capable of exporting your projects to be web compatible. And since 2018, this process is done by compiling to WebAssembly. This is a perfect example of the power that brings WASM to the table when used correctly. Game developers don’t really have to worry about writing for the web or even writing JavaScript, they’ll only need to worry about writing the code that will make the game run, and then the compilation process will take care of everything else.
  • AutoCAD web app. You read that right, Autodesk’s cad application for the web was indeed, partially ported using their old C++ code based compiled into WASM. This is a major step in showing the power and potential WASM has when it comes to re-utilizing code written for a completely different platform, in a completely incompatible language, into a modern-day browser.
  • Google Earth. You’ve probably, at least, heard of this one. This product has been around for over 15 years and used to be a desktop application. Now thanks to WASM, they’ve ported (in the same way Autodesk did for their CAD application) part of the old code into the web by compiling it to WASM. Another great example of what you can achieve with this tech.

There are over 100 more names on the list, so I invite you to take a look.

Why isn’t it more widespread then?

After seeing this, the question remains: what’s wrong with WASM then? Why isn’t it more widespread by now?

I think the answer to that question is: poor marketing.

If you think about it, the web is littered with amazing projects that never made it because they were unable to get the traction they needed with their target audience. And I think something similar is happening with WASM.

Truth be told, the potential to do amazing things and bring to the web old technology is there. The question however is: are developers aware of that?

Have you really taken the time before reading this article, to look up some examples of WASM? Do you know what it takes to do a simple “hello world”? Do you even care about bringing desktop-native applications to the browser?

I think that’s the other key problem: WASM isn’t meant for web developers, it’s meant for everyone who wants to move to the web. Web developers don’t need WASM, they already know how to use Javascript and given the amount of effort required to do a simple “hello world” in WASM (here is an example of one such case), I would understand why they don’t really care much about it.

Right now, the status quo says: if it’s a computation-intensive application, then it’s meant to be a native application.

This applies to games, VR and AR apps, platform emulations (i.e Virtual machines) and essentially most of the intended use cases for WASM. And as we all know, breaking the status quo requires a lot of effort, and most companies are just not really interested in it.

Will WASM become the new Web defacto language?

WASM has a long way to go before it can easily be implemented into a web project, let alone be the sole provider of logic for an app.

One thing to remember is that WASM isn’t meant to be written by devs, instead, it’s meant to allow devs to write in C, Go, or any other language and have that logic working on the browser.

That being said, no, I don’t think it’ll replace JavaScript anytime soon. It will however keep growing in audience numbers, as the tendency to move to the cloud helps break the status quo I mentioned before.

Whether you are a web developer or not, you can’t argue that the way web development works, you get to reach millions of users with very little effort and have a huge amount of flexibility when it comes to making changes and updating clients. This model will soon become more enticing for companies that right now, have purely native (i.e desktop or mobile) products, as time goes on and the industry keeps moving to the cloud.

In fact, WASM has the potential to keep non-web developers relevant for longer, allowing them to keep using their tech stack, just in another environment.

WebAssembly was designed and is being worked on with a huge goal in mind: bridging the gap between everything else and the web. There is still a lot of work to be done, however, the benefits can already be seen and the simple fact that 4 major browsers have support for it, means it’s gaining traction.

The question of whether it’ll become more than a simple tool used by a few is still unanswered. The jury is still out on that one.

What do you think? Do you think it’ll turn into a core tech for the web as a platform? Do you see WASM as the standard output for most other programming languages in maybe a decade or two? Or will it flop, and we’ll keep having the native vs browser conversation for a long time?

Tip: Share your reusable components between projects using Bit (Github).

Bit makes it simple to share, document, and reuse independent components between projects. Use it to maximize code reuse, keep a consistent design, collaborate as a team, speed delivery, and build apps that scale.

Bit supports Node, TypeScript, React, Vue, Angular, and more.

Image for post
Image for post
Example: React components shared on Bit.dev

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK