Delivery
10 min
You know about JavaScript, but what about WebAssembly, the new 4th language of the web (after css, js and html) ?
You run WebAssembly (or Wasm, for short) for faster performance on browsers like Firefox and Chrome. But how fast and efficient is Wasm?
Is it better than JavaScript for executing applications on web pages?
Learn more about Wasm features below.
Wasm is a type of code primarily built for modern web browsers. Developers created it for faster performance on the internet. It runs alongside JavaScript in browsers.
Here's how it works: Wasm is an open standard (software that's freely available for any developer to use) that executes binary code on the internet.
Developers can basically do what they want with Wasm, from creating gaming applications in web pages to running it as a language in serverless environments.
Developers can also use this code to execute browser operations with various languages, such as C, C++, and Rust.
The first version of Wasm (WebAssembly 1.0) has shipped in four web browsers:
So far, so good.
But what about speed?
It depends on whom you ask.
Exact speeds depend on various factors, such as the specific browser that executes the Wasm code. However, most benchmarks suggest Wasm is considerably faster than other source codes.
In one recent study, a developer discovered Wasm is faster than JavaScript across three desktop browsers on desktop computers and smartphones.
(All speed tests conducted by Aaron Turner via Medium.com.)
Differences in the speed tests above depend on whether the developer used Closure Compiler, a tool that makes JavaScript run faster on browsers.
But even when the developer used this tool, Wasm was still quicker than JavaScript across all browsers and devices.
Without Closure Compiler, Wasm was up to 40 percent faster than JavaScript.
Since these two coding languages go head to head with each other, we will share their features that sets them apart from one another.
Webassembly features:
JavaScript features:
Because Wasm is a low-level binary format with a small size, it loads faster in web browsers like Firefox, Chrome, and Safari.
When these browsers execute the Wasm code, they fetch it quicker from the server.
That makes Wasm more efficient and portable than other source codes. It's more compact than, say, JavaScript because it performs better during the execution phase. The speed tests above prove this.
Wasm also uses a linear memory and is "statically typed," which means the computer program that translates its code (the "compiler") decides if specific variables perform certain actions.
These factors increase Wasm speeds to a level that's like running binary on the command line.
It's no wonder, then, that so many companies now use Wasm to execute web applications and other functions.
Currently, major companies like Cubbit, Foretag, and Backend have incorporated Wasm into their tech stacks.
But perhaps the biggest use case so far is Google Earth, which uses Wasm to render complicated 3D models of planet Earth — something that's not possible with JavaScript.
When Wasm first launched, some Java developers had concerns about its safety, but there's no reason to be afraid. Like JavaScript, Wasm runs in environments that support it, and it's completely agile, manageable, and debuggable.
Here's what Wasm's creators have to say:
"The design of WebAssembly promotes safe programs by eliminating dangerous features from its execution semantics while maintaining compatibility with programs written for C/C++.
Modules must declare all accessible functions and their associated types at load time, even when dynamic linking is used.
This allows implicit enforcement of control-flow integrity (CFI) through structured control-flow."
So there you have it.
When we try to find out if Wasm is faster than JavaScript we should keep in mind that it depends on the device, browser, language and the use case for WebAssembly to get to a more realistic answer.
There's no doubt that Wasm is faster than other source codes, and there's lots of research to back this all up.
On the study run by Aaron Turner he found out that;
When you plan to use Wasm on desktop Chrome, which is written in AssemlyScript, for Wasm's Intended use case, then yes, Wasm is around 30% faster.
Whereas on mobile it goes further reaching a 60% faster experience. When it came to Firefox experience it was around 90% faster.
The only time when Wasm was slower than 30% was when tested on safari due to it's JS engine which handled WasmBoy very efficiently.
In one benchmark study, Wasm was faster than JavaScript across three browsers on both desktops and smartphones devices.
Without Closure Compiler — a tool that makes JavaScript run faster — Wasm was up to 40 percent quicker.
So many of the world's largest companies, including Google Earth, now use this open standard to execute powerful web applications in browsers.
Wasm is not only fast, but it's safe to use, making it an exceptional fit for developers worldwide.
Gain the benefits and advantages from Wasm application by reaching our team of expertise.
For our upcoming articles, join us by subscribing to our newsletter.