WebAssembly logo

WebAssembly – Will it replace JavaScript?

WebAssembly is an initiative led by development teams Microsoft, Mozilla and Google (lately, Apple also seems interested), which is designed to run native code in a browser (or user agent, to be more precise), in a way Safe, fast and efficient. In addition, its architecture allows multi-threaded execution with shared memory (Shared Memory Multi-threading). Web assembly can be used for frontend development. You can read more about it here.

Tl; dr;

WebAssembly is a new way to develop website interaction using binary code instead of Javascript. Both WebAssembly and Javascript will work together to enhance the website experience.

What is WASM?

The JavaScript upgrade

We can load the most critical parts of our code and add them as standard Javascript modules.

The Browser upgrade

Browsers will use the binary format generated by asm.js, which means smaller packages, faster uploads, and compile-time optimization.

We can say that it is an Abstract Syntactic Tree (AST), which is stored in binary format. It supposes a considerable improvement in runtime on Javascript. In addition, its representation at a low level will allow (over time) to be the result of the compilation of any language.

We can have source code in C#, or Java, as before, and use a WebAssembly compiler to generate that low-level code that runs in the browser. In addition, it is also designed to run on other Javascript engines, such as Node.js. When available, it will have two forms of representation: one textual and one binary. Consequently, that binary language defined by WASM can become a new universal binary for the Web.

With WebAssembly (WASM), the start-up statistics are much more optimized in all cases:

  • The decompressed code occupies 66% less than the equivalent Javascript code.
  • The uncompressed code occupies 33% less.

It is about 23 times faster to analyze syntactically (“Parsing”).

How WASM benefits developers and businesses

One of the main advantages of WASM is that it will allow us to have more in less, that means we can have the same code in a smaller size favouring the implementations of mobile platforms that will not have to download as much weight.

At the level of optimization and performance, it will allow us to improve the load of the critical parts of our application, in addition to being able to use structures compiled from other languages ​​and not having to apply them in Javascript, creating them to simulate them.

Will Web Assembly replace JavaScript?

WebAssembly workflow

The chart shown above may have helped you to understand reality. It has made clear that WASM is not a replacement of Javascript but a new feature of Javascript engine which is based on its infrastructures. So, it is clear that WASM is able to be function well in the web platform.

According to Google, this engine will have the same evolution as Javascript, everything will be retro-compatible, this means that we can use it with the previous versions. It will run at the same level as Javascript and allow synchronization from Javascript .

How will Javascript and WASM exist together?

For performance-sensitive activities, such as rendering Virtual Reality environment, WebAssembly should be used to ensure that performance is at its finest. Other frontend operations can use Javascript to develop, as the community is much bigger and it is easier to work on at the moment. Moreover, loading assets using WebAssembly is significantly faster.

Example

Let’s take a practical example. Experimenting with a prototype WASM format, Jonas Echterhoff, developer of Unity Berlin, converted using WASM the famous AngryBots demo from a Javascript code size of 19.0 MB to a gzip-compressed to 3.0 MB. This means that there is 3.0x reduction in the amount of data the browser needs to process. And 1.4x reduction in the compressed download size.

Potential Uses

There are many areas where these possibilities are welcome: Virtual Reality, Collaboration tools, information encryption, CAD software, scientific simulation, “Machine Learning” and games are just some of those options.

There is a possibility to develop application for mobile application using WebAssembly, which is similar to how React Native works. The advantage of using binary code is that we can have a light-weight and performance-optimized applications.

Summary

WebAssembly allows binary code to work on user’s browsers, which can hugely boost the performance and allow certain high power consuming technologies like Virtual Reality to work smoothly on your browser.

Thank you for reading my research on WebAssembly. You can read more about other technologies here.

Leave a Reply

Your email address will not be published.