Web Assembly: The Good Parts

So what is Web Assembly anyway?

Web Assembly is a platform, language, compiler target, and framework all at once, let me explain…

At its most basic definition, it is a very low level assembly-like language that runs efficiently on existing web browsers. In use, it will more often serve as a binary format that compilers for languages like C/C++ and Rust can target to produce web-ready modules that can be called by Javascript code and be run at near-native speeds in the browser.

Any language compiled down to the Web Assembly format will be executable on any browser, which as of this year includes Safari, Chrome, Firefox, and Edge.

Time for a brief history…

Javascript was never written to be fast for computers, it’s first priority was always to be easy to read and write for humans.

Variables in Javascript don’t need to be defined by their type until runtime and even then their types can change as the program runs. While this makes it really easy for a new dev to pick up the language and not worry about understanding the dynamics of different variable types, it is one of the main challenges of optimizing Javascript. This hasn’t been a real problem until recently however, as web applications have exploded in scope and size, the need for a faster, almost computer-first language to handle their expansion has become apparent.

Enter Web Assembly.

Development for the platform began in about 2010, spearheaded by Mozilla. Engineers started with tackling the typing system in Javascript. Asm.js was the culmination of the performance you could really get out of Javscript but even then was running 5 to 10x slower than native code.

Why Does it matter?

So what’s the big deal with web assembly?

In a nutshell, it’s speed.

Compiling code down to web assembly provides significant improvements over Javascript in build sizes, startup speed, and execution time. Even today we are already seeing near-native performance of C/C++ code running on browsers in Web Assembly.

Having a universal compiler target that is supported by all the major browsers fundamentally changes what a browser is. Already Javascript development has taken it a long way away from serving static documents, this is the next step. Developers in practically any lower level language will be able to bring their native application the the web and see the same performance as if their applications had been built, downloaded, and run natively.

This is a huge deal. Everything can run on the web browser performantly. No more downloading software, no security risks because everything is sand-boxed in a window, no need to pre-compile or install software. Just open a tab and start up your favorite game engine, or 3D CAD software, or anything…

So what does this really mean for me?

A few things.

First of all, if you’ve always been interested in learning new, lower level languages, we now live in a world where you can write a C program and import it into your web applications like any other module.

Just npm install mySuperCoolProgram.c (sort of).

As Web Assembly grows in adoption, developers will gain access to an even wider, higher performing, library of code to use in their projects.

Eventually, “installing” something could become a thing of the past. Optimized, pre-compiled code could be live streamed to you through a browser for any application, and that’s something worth getting excited about.