What is WebAssembly (Wasm)?
Code compiled or translated into Wasm form is a tightly packaged binary that can run on a client computer at near-native speed. This resembles traditional assembly language, which yields some of the fastest software performance available because code is already in a low-level form the computer's processor can run natively.
How does WebAssembly work?
This process typically involves the following four steps:
- Write. Developers can approach writing code for Wasm like any other software project, using established programming languages, software development workflows, and code management and quality standards.
- Compile. Wasm is not itself a language but rather the product of compiling and converting code written in each programming language into executable machine code. Many modern software development tools let users compile code to a Wasm binary file, as opposed to a common EXE file. Emscripten, for example, is a popular third-party Wasm compiler.
WebAssembly language support
Languages such as Rust, C/C++ and Kotlin/Native have direct compilers that translate source code directly into Wasm. Developers working in other languages, such as Java, Lua and .Net, can use third-party tools to convert code into Wasm. The Wasm interpreter can also translate code written in Python and Ruby.
WebAssembly use cases
Wasm is best suited for use cases with the following requirements:
- High performance. Wasm is useful for web browsers running processor-intensive tasks, such as math calculations, games, graphics applications, and image and video processing.
- Portability. For scenarios in which portability is essential, the same Wasm module can run on any compatible web browser and use the computer's native hardware.
Developers have already applied Wasm in a variety of real-world use cases:
- Content editing, such as audio, image and video manipulation.
- High-performance video games that run within web browsers.
- Scientific simulations, visualizations and other math-intensive tasks.
- Platform emulation, such as running specialized environments within a browser.
- Encryption and other security tasks.
- Remote desktop environments.
- Developer tools.
Pros and cons of WebAssembly
Wasm offers a variety of benefits to developers, but it also poses some potential drawbacks.
Benefits of WebAssembly
A key advantage of Wasm is its speed and efficiency. Wasm creates machine language code that runs as close to the computer's native hardware as possible, resulting in better software performance and smaller memory footprints. That code is also highly maintainable: Even though compiling to Wasm results in low-level machine language, a text format output is also generated to facilitate debugging Wasm code.
Wasm also offers broad browser and language support. Wasm is almost universally supported by every major modern web browser and is language agnostic. This means developers can write code in their preferred programming language, such as C/C++, Rust or Go, so long as their development tools can compile the code into a Wasm module. Likewise, every browser supports Wasm the same way, so developers can use the same Wasm module in any supported browser without modification.
Drawbacks of WebAssembly
A notable drawback of Wasm is its lack of garbage collection. Because Wasm does not possess native memory management, it relies on the underlying code in the original programming language to provide memory management features.
The future of WebAssembly
Wasm is still a relatively new technology, and its standard remains subject to ongoing development through the World Wide Web Consortium (W3C). Consequently, Wasm will continue to evolve as adoption and use cases grow.
Wasm use is also expanding from web browsers executing client-side code to server-side program execution, offering alternatives to enterprise and cloud computing containers. In addition, the universal portability offered by low-level Wasm code modules compiled from a standard programming language enables developers to create universal augmentations or plugins for enterprise applications.