This article is the third part of a series of posts about our journey on WebAssembly. If you’re starting out with this article, you might want to start there.

In the last article, we presented how JavaScript evolved over the years and how Just in Time Compilers (JIT) works in this language, making the JS execution faster. This explanation gives us a base to helps us to compare the performance of JavaScript with WebAssembly. But what is WebAssembly?

What is WebAssembly?

WebAssembly or WASM is a Compiler Target (code generated by compilers) with a binary format, which allows us to execute C, C++, and Rust on the browsers with a performance close to native code.

An exciting aspect of WebAssembly is that it wasn’t made to be a substitute for JavaScript but to work alongside it. At the same time, this combination can provide the performance of typed/compiled languages and the flexibility of JavaScript. Using the WebAssembly API on JavaScript, you can load modules WASM on JS application and share functionalities between them.

In the last article, after understood how JavaScript is fast, we wondered which technology could help us to have the same jump of performance JIT brought in 2008. WebAssembly is this technology. But to understand how a WASM code can be faster than JavaScript, we need to analyze how Javascript engine conceptually treats both.

For the sake of visualization, the life cycle comparison between JavaScript and WebAssembly code could theoretically be taken as the following image:

Theoretically comparison between JavaScript and WASM code life cycle.

The Common misconceptions regarding WebAssembly

These are the most common misconceptions I’ve seen when people are discussing about this topic:

As we saw above and on previous articles, WASM is theoretically faster than JavaScript, but how does it seem in practice? This is what we are going to find out in the next article.

Links