Home › Categories › Web Development › WebAssembly

WebAssembly

From WikiTech, the encyclopedia of technology

Technology · Web Development · 5 min read · 942 words · Updated

WebAssembly
Technology
WebAssembly — article photograph or illustration
Image placeholderPlace the file shown below in the assets/articles folder
File: webassembly.webp
Standardised byW3C
First browser support2017
W3C Recommendation5 December 2019
Websitewebassembly.org

WebAssembly (Wasm) is a compact binary format for a stack-based virtual machine. Code written in languages such as Rust, C and C++ can be compiled to it and run in a sandbox.

History

Browsers shipped a first version in 2017, and the World Wide Web Consortium (W3C) made WebAssembly 1.0 a Recommendation on 5 December 2019.

Architecture

A Wasm module contains functions, linear memory, tables and imports and exports. The runtime validates the module before executing it. Modules can only access the outside world through imported functions, which gives the sandbox its security properties.

Key mechanisms

WASI, the WebAssembly System Interface, defines how modules access files and networking outside browsers. Runtimes include Wasmtime and Wasmer.

Adoption

Wasm is used for image and video processing, games, and running existing native libraries in the browser.

Ecosystem

Wasm does not replace JavaScript; it interoperates with it. Direct DOM access still goes through JavaScript.

Module format and execution

A WebAssembly module contains type declarations, functions, tables, memory definitions, globals and references to imported resources. The binary format is compact and designed for efficient decoding. A runtime validates the module before executing it, checking structural rules and type consistency. This validation prevents many classes of malformed code from reaching execution, although it does not guarantee that a program's logic is correct or harmless.

WebAssembly uses a stack-based instruction model. Functions operate on typed values, and control-flow constructs define how execution moves through a module. A module can import functions or memory from its host environment and can export functions or other resources for the host to call. In a browser, JavaScript commonly provides the bridge between Wasm code and web APIs such as the DOM.

Compilation and language support

Languages including C, C++ and Rust can compile to WebAssembly using suitable toolchains. The compiler translates a source program into a module, and the browser or standalone runtime validates and executes it. This can make existing libraries available in web applications without rewriting every component in JavaScript. The performance benefit depends on the workload, data-transfer overhead, runtime support and quality of the compiler output.

WebAssembly is not limited to browsers. Standalone runtimes can execute modules in command-line tools, server applications, plugin systems and edge-computing environments. This portability depends on the host providing the imports the module expects. A module that relies on browser APIs cannot automatically run in a minimal server runtime without an equivalent host interface.

Memory and the host boundary

Traditional WebAssembly modules use linear memory, a contiguous address space that code accesses through defined instructions. The host can control which memory is provided and can limit how much it grows. A module does not automatically gain access to arbitrary files, network sockets or operating-system resources. Those capabilities must be made available through imports or a standardised host interface.

The sandbox boundary is useful for running code from different sources, but it is not a substitute for resource limits or a complete security policy. A module can still consume excessive CPU or memory, and a vulnerable host function can expose privileges beyond the module's intended scope. Hosts should validate inputs, restrict capabilities and impose limits on untrusted workloads.

WASI and component systems

The WebAssembly System Interface (WASI) defines interfaces that allow modules to interact with selected operating-system-like services. It aims to make modules more portable across runtimes while keeping capabilities explicit. Different WASI versions and proposals provide different interfaces, so developers should check which features a target runtime supports rather than assuming that every module can access the same resources.

The component model and interface description work seek to make it easier for independently compiled modules to communicate through well-defined types and contracts. These ideas are important for plugin architectures and portable server-side applications, where modules may be written in different languages and deployed in different environments.

Use cases and trade-offs

WebAssembly is used for computationally intensive browser features, games, media processing, language runtimes, developer tools and sandboxed extensions. It can help reuse existing code and provide a portable execution target. It is not automatically faster than JavaScript, and frequent communication between JavaScript and Wasm can reduce performance if data is copied or converted inefficiently.

Wasm also has limitations around debugging, system integration, package size and access to platform APIs. The ecosystem is improving, but the best fit depends on the application. WebAssembly complements JavaScript and existing operating systems rather than replacing them: it supplies a portable execution environment that can be embedded wherever a host is willing to provide the necessary interfaces.

Choosing WebAssembly for a project

WebAssembly is most useful when portability, sandboxing or reuse of existing compiled code provides a clear benefit. A browser application that performs substantial image processing may benefit from moving that computation into a Wasm module, while a simple form-heavy page may gain little. Developers should measure startup time, module size, memory use and the cost of passing data between JavaScript and Wasm. The runtime environment also matters: a module designed for a browser may need different imports to run on a server or in a plugin host.

Editorial connections and engineering implications

WebAssembly is a portable binary instruction format that runtimes validate before execution. A host controls access to files, networks, clocks and other resources through explicit imports or APIs. This makes the execution boundary clearer than giving a module unrestricted access to a machine. Wasm is used in browsers as well as servers, edge runtimes, plugins and command-line tools, provided the needed runtime features and host interfaces are available.

Performance depends on the workload and the boundary with the host. Calls between JavaScript and Wasm, memory copies and startup costs can outweigh the benefit for small tasks. Large numerical kernels or reuse of native libraries may be better candidates. C, C++ and Rust can compile to Wasm, while WASI defines interfaces for non-browser environments. This connects Wasm to Rust, C and the web platform.

See also

  • C++ – A general-purpose, statically typed language that extends C with classes, templates and zero-overhead abstractions.
  • JavaScript – The programming language that powers interactive web pages and a large ecosystem of browser, server and desktop software.
  • CSS – The style sheet language that controls the presentation, layout and responsive behaviour of HTML documents.
  • HTML – The standard markup language used to structure documents and applications on the World Wide Web.
  • C (programming language) – A general-purpose, statically typed systems programming language created at Bell Labs in the early 1970s.
  • Graphics Processing Unit (GPU) – A processor designed to perform many data-parallel operations, first for graphics and now widely used in scientific and AI computing.
  • Rust – A compiled systems programming language that enforces memory safety through ownership and borrowing without a garbage collector.
  • HTTP/3 – The third major version of the Hypertext Transfer Protocol, which runs over QUIC instead of TCP.

References

  1. ↑ WebAssembly.org (webassembly.org)