WebAssembly — What’s the big deal ?

Credits: Mozilla Hacks

I have been hearing a lot about WebAssembly lately. In order to satisfy my curiosity I started digging deeper about it. And so, here I am giving quick overview about WebAssembly.

What is WebAssembly ?

“WebAssembly is a new type of code that can be run in modern web browsers and provides new features and major gains in performance.” — Mozilla developers network.

The web mainly consists of documents represented in HTML & CSS. Javascript(JS) gives HTML support for interactions between different components. JS is executed in the browser in a secure sandbox environment called Javascript runtime or JVM.

Where does WebAssembly come in this picture ?

Credits: Pluralsight — Barry Luijbregts

WebAssembly(WASM) sits along with JS in the Javascript runtime sandbox and gets executed the same way. Since, its in a sandbox environment, it also has the same security like JS. Its represented as a Abstract Syntax Tree (AST) and build into binary format. File format for WebAssembly is wasm. Its already in a binary format that the Javascript Runtime can understand without interpreting the language. It also has access to WebAPI, which can access things like DOM, Audio and Web Sockets.

Why do we need it ?

As mentioned above, Wasm modules are in the same sandbox as JS. Then, why do we need WebAssembly at all. Although I mentioned it in theory, WebAssembly comes with features that will change how you have built web applications till now. Here are the major ones:

  1. Its fast. Since, wasm is already in a binary format and no additional interpretation is needed, it executes much faster than javascript modules. This will increase startup speed and optimization for applications way better than JS. It will run code at near native speed.
  2. Compilation target for various other high-level languages. Ever imagined that you would be able to build web application with C/C++/C# or RUST ? Surprise!!!!! Now you can compile all of these languages into wasm. Think about the various applications you were never able to run in browser because the underlying language is not supported. This is also means, all those haters of JS will now be able to work together with JS builders. We are getting a pool of resources :)
  3. Supported by browsers without any plugins. Major browsers are supporting wasm already! You dont have to install any plugin to get going with it.
  4. Javascript code can run wasm modules. You might think, what will happen to all of the existing javascript modules and applications. Wasm is not here to replace JS, it will co-exist with various JS frameworks that we have right now. You can import and include wasm modules inside JS code as well.
  5. Can run on Mobile Devices. Wasm also can run in WASM runtime apart from JS runtime. Devices like Android or IOS can easily provision this runtime and that would give wasm modules access to the APIs available.
  6. Performance boost. Using WebAssembly gives applications a performance boost which we never has before from JS. This actually comes from the usage of features in high level languages like C/C++ etc.

WebAssembly Use-cases

  • Video/audio editing tools
  • Video/audio streaming tools
  • Gaming
  • Video/Audio calling
  • Virtual/Augmented reality
  • Artificial Intelligence

The history

April 2015 — A new group called WebAssembly community group was started. This community group was formed by W3C committee. It consisted of people from major browser vendors, who wanted to create a new code format other than javascript that can work much faster and more portable for web applications.

June 2015 — The group made a public announcement that they are working on a new standard called WebAssembly.

March 2016 — The community posted the definition of core features and standards that would be in WebAssembly. Some of the browsers have implemented these features as experiments.

October 2016 — A Minimal Viable Product was announced for the community to try out. This was supported by all major browsers.

January 2017 — A logo was choosen.So far all of the work is done by the community and everything is open in github.

March 2017 — Major browsers like chrome, Edge, Firefox and Webkit reached consensus about a minimal viable product. At this stage the community decided they needed more implementation experience and significant usage in order to help move forward with further design.This marked the end of the preview period for the browsers.

August 2017 — W3C formed a WebAssembly working group to create standards for WebAssembly just like HTML, CSS and Javascript.

September 2017 — Safari also started support for WebAssembly.

February 2018 — W3C released for draft specification for WebAssembly. This contain standards for developing WebAssembly.

More Resources