Why Does WebAssembly Matter?

Shutterstock/Andrey Suslov

WebAssembly is a binary-instruction format that can be executed in web browsers. It provides a sandboxed execution environment with near-native performance, eliminating most of the overheads associated with JavaScript on web pages.

WebAssembly (Wasm) is low-level machine code that runs in a stack-based virtual machine. This means that it’s much closer to your hardware than JavaScript. That needs to be parsed and fully interpreted before it can run.

Creating Wasm is a bit more involved than writing JavaScript. Although you can hand-code it in Wasm Text Format, this is low level and equivalent to writing assembly code for native execution. More often, you’ll write in an established programming language and compile to Wasm. (More on that later.)

Why Does Wasm Actually Matter?

If the increase in rich web applications is anything to go by, developers, by and large, are pretty comfortable with writing JavaScript. It’s evolved considerably over the past decade with new syntax features and improvements in browser performance. These have elevated it from simple scripts to a language that’s capable of supporting complex, self-contained applications. Why is WebAssembly needed, then?

Wasm doesn’t replace JavaScript. It’s targeted at specific use cases where JavaScript is still a hindrance and will possibly always be. Of these cases, performance is where Wasm particularly excels.

JavaScript-heavy websites have a tendency to feel sluggish and eat up memory. This is especially noticeable on mobile devices, where web apps still lack the “feel” of their native counterparts.

Because Wasm sits so much closer to the hardware, it offers a level of performance that’s barely distinguishable from native apps. This opens the web to a new class of performance-critical applications. If it runs on your desktop, it could run in the browser without any perceptible performance slowdown.

Do We Need More Web Performance?

There will always be an argument that some apps are simply best suited to desktop use. The web provides its own benefits, though, particularly around broad distribution.

Publishing your app on the web gives you the widest possible audience. Anyone can access it from whichever device they own. This increases convenience for your users and means that you have one codebase to maintain.

The real question isn’t whether we need more web performance: Instead, we should be asking whether we need more applications on the web. To answer that question, we can look to functionality-heavy sites that have already adopted Wasm.

AutoCAD is computer-aided design software for architects and engineers. The latest web version debuted at Google I/O in 2018. It uses Wasm to consume components of the existing desktop codebase as is. Some of the code dates back 35 years but now runs in the browser.

Another example is Figma, which already used the asm.js JavaScript subset to optimize its performance. By moving to Wasm, Figma noted a 3x performance improvement. Google uses Wasm too, relying on it to bring Google Earth onto the web for all.

These highly complex applications couldn’t previously exist on the web. If they did, they ran with severe performance penalties compared with their desktop counterparts. Wasm is the architecture necessary to complete the web’s transition from document-oriented pages to a complete application platform. You can even play Doom 3!

Increasing Developer Choice

Beyond performance, WebAssembly matters because it gives developers more flexibility and choice. Excluding the legacy of Flash, Java, and ActiveX plugins, JavaScript has been your only choice when writing code for the browser.

That situation has now been transformed. WebAssembly is a low-level format that other languages compile to. C, C++, C#, Java, Python, Rust, and many more besides are capable of outputting WebAssembly modules. This gives developers many more options when creating code for the web.

You still need JavaScript to load your Wasm modules, but that’s about it. You could implement all of your project’s functionality using your chosen language, and then compile it down to Wasm for the browser.

Developers can now write for the web in the language that best suits them and their application. That might be a strongly typed, object-oriented language, or something focused on functional programming. No longer are you restricted to JavaScript’s loose typing and object prototypes.

Facilitating Code Reuse

WebAssembly brings substantial benefits when it comes to code reuse. You can bring your shared libraries to the web without reimplementing them in JavaScript. This could save hours, days, or weeks of your time.

Using C# as an example, you might have a .NET DLL that contains convenience methods used by your server-side code and your desktop application. Previously, you’d need to implement those methods in JavaScript when it came time to build your web app.

With Wasm, you can recompile your DLL using WebAssembly as the target. The same code becomes accessible in the browser. Wasm reduces waste and duplicate engineering by letting you use what you already have.

Historically, this has only really been possible if your backend used Node.js. You could abstract common logic into a JavaScript library ready for reuse in the frontend. Now, you can work with libraries written in any language.

This works even if you’ll stick with JavaScript for the bulk of your web app. You can interface with Wasm modules through JavaScript, so you can still use your DLL of shared functions. Asynchronous APIs let you exchange data with Wasm so that you can call functions and get their return values.


WebAssembly is easily dismissed as an obscure technology with little relevance to today’s web apps. Wasm is really targeting the web of tomorrow, where desktop-class apps will run with native performance.

It’s important to look beyond the headline benefits, too. Wasm isn’t just about speed increases. It can also reduce time-to-ship for development teams, especially those that work cross-platform or share logic between the client and the server. Part of the excitement around WebAssembly derives from the web’s transformation into a compilation target, instead of it being a completely standalone platform. Building for the browser no longer means writing JavaScript.

Here, in 2021, WebAssembly adoption remains relatively low. Projects that use it have reported successes—you only need to try Figma or Google Earth to appreciate the Wasm performance standard. You’re likely to see more of Wasm over the next few years as apps, both new and old, are brought into the browser.

Source link

Avatar photo
Lisa is avid technical blogger. Along with writing a good articles, She has close interests in gadgets, mobile and follows them passionately.

Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here