Bringing the Web Up to Speed
with WebAssembly
By Andreas Rossberg, Ben L. Titzer, Andreas Haas, Derek L. Schuff, Dan Gohman, Luke Wagner, Alon Zakai, J.F. Bastien,
and Michael Holman
DOI: 10.1145/3282510
Abstract
The maturation of the Web platform has given rise to sophisticated Web applications such as 3D visualization, audio
and video software, and games. With that, efficiency and
security of code on the Web has become more important
than ever. WebAssembly is a portable low-level bytecode
that addresses these requirements by offering a compact
representation, efficient validation and compilation, and
safe execution with low to no overhead. It has recently been
made available in all major browsers. Rather than committing to a specific programming model, WebAssembly is an
abstraction over modern hardware, making it independent
of language, hardware, and platform and applicable far
beyond just the Web. WebAssembly is the first mainstream
language that has been designed with a formal semantics
from the start, finally utilizing formal methods that have
matured in programming language research over the last
four decades.
1. INTRODUCTION
The Web began as a simple hypertext document network
but has now become the most ubiquitous application platform ever, accessible across a vast array of operating systems and device types. By historical accident, JavaScript is
the only natively supported programming language on the
Web. Because of its ubiquity, rapid performance improvements in modern implementations, and perhaps through
sheer necessity, it has become a compilation target for
many other languages. Yet JavaScript has inconsistent performance and various other problems, especially as a compilation target.
WebAssembly (or “Wasm” for short) addresses the prob-
lem of safe, fast, portable low-level code on the Web. Previous
attempts, from ActiveX to Native Client to asm.js, have fallen
short of properties that such a low-level code format should
have:
• Safe, fast, and portable semantics:
– safe to execute
– fast to execute
– language-, hardware-, and platform-independent
– deterministic and easy to reason about
– simple interoperability with the Web platform
• Safe and efficient representation:
– maximally compact
– easy to decode, validate and compile
– easy to generate for producers
– streamable and parallelizable
The original version of this paper was published in
Proceedings of the 38th ACM SIGPLAN Conference on
Programming Language Design and Implementation
(Barcelona, Spain, June 18–23, 2017), 185–200.
Why are these goals important? Why are they hard?
Safe. Safety for mobile code is paramount on the Web, since
code originates from untrusted sources. Protection for mobile
code has traditionally been achieved by providing a managed
language runtime such as the browser’s JavaScript Virtual
Machine (VM) or a language plugin. Managed languages
enforce memory safety, preventing programs from compromising user data or system state. However, managed language runtimes have traditionally not offered much for low-level code,
such as C/C++ applications that do not use garbage collection.
Fast. Low-level code like that emitted by a C/C++ compiler
is typically optimized ahead-of-time. Native machine code,
either written by hand or as the output of an optimizing compiler, can utilize the full performance of a machine. Managed
runtimes and sandboxing techniques have typically imposed
a steep performance overhead on low-level code.
Universal. There is a large and healthy diversity of programming paradigms, none of which should be privileged
or penalized by a code format, beyond unavoidable hardware constraints. Most managed runtimes, however, have
been designed to support a particular language or programming paradigm well while imposing significant cost on
others.
Portable. The Web spans not only many device classes,
but different machine architectures, operating systems, and
browsers. Code targeting the Web must be hardware- and
platform-independent to allow applications to run across all
browser and hardware types with the same deterministic
behavior. Previous solutions for low-level code were tied to a
single architecture or have had other portability problems.
Compact. Code that is transmitted over the network
should be small to reduce load times, save bandwidth, and
improve overall responsiveness. Code on the Web is typically
transmitted as JavaScript source, which is far less compact
than a binary format, even when minified and compressed.
Binary code formats are not always optimized for size either.
WebAssembly is the first solution for low-level code on
the Web that delivers on all of the above design goals. It is
the result of an unprecedented collaboration across all
a WebAssembly engines are not assumed to spend time on sophisticated
optimizations, because producers usually can take care of that more cheaply
offline. Hence WebAssembly does not magically make code faster. But it
allows other languages to bypass the cost and complexity of JavaScript.