How fast and efficient is Wasm?

WebAssembly is a type of code built for modern web browsers. Wasm is available for developers to create gaming applications on the web pages.

Digital Delivery
-
7 min
Digital Delivery
/
How fast and efficient is Wasm?

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.

A (very) brief history of Wasm

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.

How does Wasm work

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:

  1. Chrome
  2. Firefox
  3. Safari
  4. Microsoft Edge

So far, so good.

But what about speed?

How fast is Wasm, really?

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.

  • Wasm is 1.15-1.67 times faster than JavaScript on Google Chrome on a desktop.
  • Wasm is 1.95-11.71 times faster than JavaScript on Firefox on a desktop.
  • Wasm is 1.02-1.38 times faster than JavaScript on Safari on a desktop.
  • Wasm is 1.25-2.59 times faster than JavaScript on Chrome on a Moto G5 Plus smartphone.
  • Wasm is 1.84-16.11 times faster than JavaScript on Firefox on a Moto G5 Plus smartphone.
  • Wasm is 1.07-1.23 times faster than JavaScript on Safari on an iPhone 6s.

(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.

WebAssembly vs 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:

  • it's fast(er)
  • it's delivered via a small sized binary format
  • it's strongly typed

JavaScript features:

  • it's dynamically typed
  • it's highly flexible
  • it's delivered in human-readable code

Why is Wasm so fast?

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.  

Is Wasm safe?

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.

Final verdict

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.

Published on
September 17, 2021

Industry insights you won’t delete. Delivered to your inbox weekly.

Other posts