iTranslated by AI
An Introduction to WASM and WASI: A Gentle Guide to Understanding the Latest Ecosystem News ๐ฎ

1. Introduction
1.1. Background and Purpose of the Emergence of WebAssembly (WASM)
With the evolution of the Web, there has been an increasing demand to process more advanced and computationally intensive applications on the browser. However, JavaScript, which has traditionally been the programming language of the Web, is a dynamically typed language and faces limitations in runtime optimization.
Particularly in large-scale applications or performance-critical processes, the following challenges existed:
| Challenge | Description |
|---|---|
| Performance | Although optimization of JavaScript engines has improved, a performance gap still exists compared to languages that are statically typed and pre-compiled. |
| Startup Time | Large-scale JavaScript code may take time to parse, compile, and start execution. |
| Language Selection | Web front-ends were limited to JavaScript (or AltJS like TypeScript), making it difficult to leverage existing code assets written in other languages such as C/C++, Rust, or Go on the Web. |
To solve these challenges and enable performance close to native code on the Web platform, along with development in diverse languages, WebAssembly (WASM) was standardized by the W3C (World Wide Web Consortium) working group. WASM is a low-level binary instruction format designed for high-speed, efficient, and secure execution.
1.2. Background and Purpose of the Emergence of WebAssembly System Interface (WASI)
WASM was initially developed with a primary focus on use in Web browsers. However, its characteristics such as portability, performance, and security began to attract attention in environments outside the Web (server-side, edge computing, embedded systems, etc.).
However, WASM itself does not define standard methods for accessing OS functions such as file systems, networks, or clocks. If each WASM runtime provides access to OS functions in its own way, the key advantage of WASMโ"portability"โwould be lost, defeating the purpose.
To solve this problem, the WebAssembly System Interface (WASI) emerged.
WASI is a standard interface (API) specification for WASM modules to access OS functions securely and portably. WASI aims to operate identically on any WASM runtime, regardless of specific OS or hardware.
In other words, these ecosystems have a hierarchical structure: applications are converted into WASM modules, which run on a WASM runtime providing basic execution functions. When coordination with the OS is required, running them on a WASM runtime that implements WASI enables consistent execution across different platforms.
+----------------------------------+
| Application |
+----------------------------------+
โ
+----------------------------------+
| WASM Module |
+----------------------------------+
โ
+----------------------------------+
| |
| WASM Runtime |
| (with/without WASI API) | โ Basic WebAssembly execution functions
| | โ + Optional standardized access to
| | OS resources (WASI)
+----------------------------------+
โ
+----------------------------------+
| Operating System |
+----------------------------------+
1.3. Historical Background and Development
Based on the background and challenges mentioned above, let's look back at the historical development of WebAssembly and WASI. Below is a timeline showing the major milestones for WebAssembly and WASI.
| Era | Event | Details |
|---|---|---|
| 2013 | Emergence of asm.js | Mozilla developed asm.js as a subset of JavaScript. It appeared as a technology to execute C/C++ code at high speed by converting it to JavaScript. The Emscripten compiler outputs this. |
| 2014 | Initial Considerations | Based on the experience with asm.js, the need for a dedicated binary format free from the constraints of JavaScript began to be recognized. |
| 2015 | Announcement of the WebAssembly Concept | Joint development of WebAssembly by Mozilla, Google, Microsoft, and Apple was announced. Design started as a browser-native binary format. |
| 2015 | Start of Initial Specification Formulation | Establishment of the W3C Community Group. Definition of scope and requirements for the MVP (Minimum Viable Product) began. |
| 2016 | Prototype Implementation | Initial implementations progressed in various browser engines. Implementation work was carried out in Chrome (V8), Firefox (SpiderMonkey), Safari (JavaScriptCore), and Edge. |
| 2017 | Completion of MVP Specification | Completion of the specification for the minimal implementation set (MVP) of WebAssembly 1.0. Definition of the basic feature set (integer and floating-point arithmetic, linear memory, function calls). |
| 2017 | Support by Major Browsers | Support for WebAssembly was included in the stable versions of all major browsers: Chrome, Firefox, Edge, and Safari. |
| 2018 | Ecosystem Growth | Development of toolchains (Emscripten, wasm-bindgen, etc.) and frameworks. Proposals for extensions such as Threads, SIMD, and Reference Types began. |
| 2019 | Announcement of WASI | Mozilla announced the WebAssembly System Interface (WASI). Standardization of WASM execution environments outside the browser began. |
| 2019 | W3C Recommendation | WebAssembly 1.0 was formally standardized as a W3C Recommendation, becoming an official specification of the Web platform. |
| 2019 | Establishment of Bytecode Alliance | Mozilla, Fastly, Intel, and Red Hat took the lead in establishing the Bytecode Alliance to promote the WebAssembly and WASI ecosystem. |
| 2020 | Reference Types Implementation | Implementation of the Reference Types extension was introduced into major browsers. References to JavaScript objects became possible. |
| 2020- 2021 |
Maturity of Non-Browser Runtimes | Expansion of features and performance improvements for non-browser runtimes such as Wasmtime, Wasmer, and WasmEdge. |
| 2021 | SIMD Support | The SIMD (Single Instruction Multiple Data) instruction set was implemented in major browsers, improving the performance of vector operations. |
| 2022 | Component Model Proposal | Proposal and initial implementation of the WebAssembly Component Model. Aiming to improve interoperability between modules. Docker announced support for WebAssembly containers. |
| 2023 | WASI Preview 2 | Progress in the development of the Preview 2 set of improved WASI APIs. Integration with the Component Model. Experimental support for WebAssembly GC began in Chrome and Firefox, improving support for GC-dependent languages such as Java. |
| 2024~ | Practical Application of Key Technologies | WASI Preview 2 (stable version) was released and underwent extensive testing. The Component Model moved to Phase 3 (implementation phase), with major browser vendors committing to implementation. Major cloud providers expanded their adoption of WebAssembly in edge computing platforms. |

2. Key Concepts of WebAssembly
2.1. What is WebAssembly?
WebAssembly (WASM) is a low-level binary instruction format (bytecode) for a stack-based virtual machine that can be executed in web browsers.
It has the following characteristics:
| Characteristic | Description |
|---|---|
| Fast | Designed to run at speeds close to native code. The binary format is fast to decode and efficiently converted to machine code by JIT (Just-In-Time) or AOT (Ahead-Of-Time) compilation. |
| Efficient | The compact binary representation reduces network transfer volume and storage capacity. |
| Secure | Operates in a sandboxed execution environment, ensuring memory safety. Features of the host environment (browser or runtime) can only be accessed through explicit imports. |
| Portable | Independent of specific hardware or OS, capable of running in any environment that supports WASM (web browsers, servers, mobile devices, etc.). |
| Language Independent | Can be compiled from various programming languages such as C, C++, Rust, Go, C#, and AssemblyScript. Existing code assets can be utilized on the Web and other platforms. |
WASM is not intended to replace JavaScript, but rather to work in coordination with JavaScript. It allows for a division of roles where computationally intensive processes are executed in WASM, while UI operations and Web API access are handled by JavaScript.
2.2. Design Principles
Based on the characteristics mentioned above, WebAssembly sets the following design goals.
| Design Goal | Description |
|---|---|
| Fast, Safe, and Portable Semantics | โข Fast: Achieving execution performance nearly equivalent to native code. โข Safe: Ensuring execution in a memory-safe, sandboxed environment. โข Well-defined: Defining programs and their behavior clearly, both formally and informally. โข Hardware-independent: Capable of running on all modern architectures, including mobile, desktop, and embedded systems. โข Language-independent: Designed without favoring any specific language or programming model. โข Platform-independent: Embeddable in browsers, standalone VMs, and other environments. โข Open: Allowing simple and universal interoperability with the environment. |
| Efficient and Portable Representation | โข Compact: A binary format that is smaller than text or native code and can be transmitted quickly. โข Modular: Programs can be split into small parts, allowing them to be transmitted, cached, and consumed individually. โข Efficient: Capable of fast, single-pass decoding, validation, and compilation, whether JIT or AOT. โข Streamable: Processing can begin before all data has been received. โข Parallelizable: Decoding, validation, and compilation can be split into many independent parallel tasks. โข Portable: Assumes only widely supported features and does not depend on specific architectures. |
2.3. Module Structure
The basic unit of compilation and execution in WebAssembly is the module. A module is a self-contained unit that encapsulates the following elements:
Module
โโโ Magic Number & Version (Binary format identifier and version info: 0x00 0x61 0x73 0x6D + version)
โโโ Custom Section (For debug info or extensions; can have multiple)
โโโ Type Section (Function type declarations)
โโโ Import Section (Definitions for imports from the external environment)
โโโ Function Section (Indices for function types)
โโโ Table Section (Reference tables for indirect function calls)
โโโ Memory Section (Linear memory definition)
โโโ Global Section (Global variable definitions)
โโโ Export Section (Features the module exposes to the outside)
โโโ Start Section (Function executed when the module is loaded)
โโโ Element Section (Table initialization data)
โโโ Code Section (Bytecode implementations of function bodies)
โโโ Data Section (Memory initialization data)
โโโ Data Count Section (Number of data segments, simplifying single-pass validation)
Each section has a specific purpose and defines the module's behavior. The presence of sections is optional and they are included as needed.
Here are a few characteristic points:
- Function definitions are split into type declarations (Type Section/Function Section) and implementations (Code Section), enabling parallel and streaming compilation.
- Custom Sections can be placed in multiple locations at any position, but other sections must appear at most once and in a prescribed order.
- Each section can be omitted, and an omitted section is equivalent to an empty section.
- Module validation confirms that the lengths of the Function Section and Code Section match, and that the Data Count Section matches the actual number of data segments.
2.4. WebAssembly Type System
The basic value types defined in the WebAssembly core specification (MVP: Minimum Viable Product) are as follows:
| Type | Description |
|---|---|
i32 |
32-bit integer |
i64 |
64-bit integer |
f32 |
32-bit floating-point number (IEEE 754) |
f64 |
64-bit floating-point number (IEEE 754) |
These types are used for values on the stack, local variables, global variables, and function arguments and return values. WASM is statically typed, and the type of every value is determined at compile time or during validation.
The following types have been added through subsequent extension proposals:
| Extended Type | Description | Specification Status |
|---|---|---|
v128 |
128-bit vector | SIMD extension (widely supported) |
funcref |
Function reference | Reference Types extension (widely supported) |
externref |
External object reference | Reference Types extension (widely supported) |
The addition of Reference Types (funcref and externref) allows for handling function references and opaque references to host environment objects (e.g., JavaScript objects, DOM nodes). This has strengthened the integration between WASM and the host environment.
2.5. WebAssembly Formats
WASM primarily has two formats.
2.5.1. Binary Format (.wasm)
The binary format is designed to efficiently represent the module structure mentioned earlier and is the format actually transmitted to and loaded by the execution environment. The recommended file extension is ".wasm," and the media type is "application/wasm."
| Feature | Description |
|---|---|
| Linear Representation of Abstract Syntax | Represents the hierarchical abstract syntax of the module as a one-dimensional byte sequence. This representation corresponds to the section structure described in section 2.3. |
| Definition Based on Attribute Grammar | The binary format is formally defined as an attribute grammar; a module is only valid if the byte sequence is generated by this grammar. This grammar implicitly defines the decoding (parsing) algorithm. |
| Identifier and Version | Each module starts with the magic number \0asm (0x00 0x61 0x73 0x6D), followed by a version number (currently 1). This allows for immediate identification of WASM files. |
| Representation of Data Structures | โข Vectors: Length (u32 value) + sequence of elements โข Numeric types: i32 is 0x7F, i64 is 0x7E, f32 is 0x7D, f64 is 0x7C, etc. โข Limits: Pairs of minimum (required) and maximum (optional) values |
| Decoding and Validation Efficiency | Designed for single-pass decoding, validation, and compilation, supporting streaming and parallel processing. This allows even large modules to be processed efficiently. |
| Extensibility | Designed to support future feature extensions while maintaining the basic representation. New features can be added without changing the version number. |
2.5.2. Text Format (.wat - WebAssembly Text Format)
Alongside the binary format, WebAssembly provides a human-readable and writable text representation based on S-expressions. The file extension ".wat" is used, making it suitable for development, debugging, and educational purposes.
| Feature | Description |
|---|---|
| S-expression Syntax | A Lisp-like syntax enclosed in parentheses that intuitively represents the hierarchical structure of the module. Each instruction or structure is written in a parenthesized format consisting of a keyword and arguments. |
| Module Representation | Capable of representing all features of the binary format, and the section structure of the module can be explicitly described. (module ...) is the root element. |
| Naming Symbols | While the binary format relies on index-based references, the text format allows the use of identifiers in the $name format, significantly improving readability. |
| Instruction Representation | Stack machine instructions are represented in prefix notation; for example, (i32.add) represents an integer addition operation. The nested structure of instructions makes the flow of stack operations visually easier to understand. |
| Comments | Supports line comments starting with ;; and block comments enclosed in (;...;), allowing for the description of the code's intent. |
| Conversion Tools | Tools like wat2wasm (text โ binary) and wasm2wat (binary โ text) allow for accurate mutual conversion between the two formats, increasing the flexibility of the development workflow. |
Below is an example of a module that defines a simple addition function and exports it.
(module
;; Function that takes two 32-bit integers and returns their sum
(func $add (param $lhs i32) (param $rhs i32) (result i32)
local.get $lhs ;; Push the first parameter onto the stack
local.get $rhs ;; Push the second parameter onto the stack
i32.add) ;; Add the top two values on the stack
;; Expose the function to the outside under the name "add"
(export "add" (func $add))
)

3. WebAssembly Compilation Process
3.1. Pipeline for Converting Source Languages to WASM
Compiling high-level programming languages into WebAssembly generally involves the following stages:
| Stage | Processing Content |
|---|---|
| 1. Frontend Processing | โข Lexical and syntax analysis of source code โข Generation of Abstract Syntax Tree (AST) โข Semantic analysis and type checking โข Conversion to language-specific intermediate representation |
| 2. Optimization Phase | โข Language-specific optimizations โข General optimizations in common intermediate representations like LLVM IR โข Loop optimization, inlining, constant folding, etc. |
| 3. WebAssembly Generation | โข Conversion to WebAssembly instructions โข Determination of linear memory layout โข Optimization of memory access patterns โข Generation of the WebAssembly binary ( .wasm) |
Many languages leverage existing compiler infrastructure (especially LLVM) to achieve WebAssembly support. This makes it relatively easy to generate well-optimized WASM code.
3.2. Compiler Toolchains for Major Languages
3.2.1. C/C++: Emscripten
Emscripten is the most mature toolchain for converting C/C++ code into WebAssembly.
โโโโโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โC/C++ Sourceโ โ โ Clang โ โ โ LLVM IRโ โ โ Binaryen โ โ โ WebAssembly โ
โโโโโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
| Component | Role |
|---|---|
| Clang | Frontend processing for C/C++ (syntax analysis, type checking, etc.) |
| LLVM | Optimization at the intermediate representation level (loop optimization, vectorization, etc.) |
| Binaryen | WebAssembly-specific optimization and binary generation |
Emscripten's greatest strength is that it also provides polyfills to emulate browser environments, allowing existing C/C++ applications to be ported with minimal changes.
3.2.2. Rust
Rust provides first-class support for WebAssembly in its official toolchain.
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ
โRust Source โ โ โ rustc (LLVM) โ โ โ WebAssembly โ
โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ
Rust has multiple WebAssembly targets:
| Target | Use Case |
|---|---|
| wasm32-unknown-unknown | Minimal target for browsers or headless environments |
| wasm32-wasi | Applications using the WASI system interface |
| wasm32-unknown-emscripten | Utilizes Emscripten system libraries (Legacy) |
The Rust ecosystem includes key tools that support WebAssembly development:
- wasm-bindgen: Generates type-safe bindings between Rust and JavaScript.
- wasm-pack: Generates easy-to-use npm packages from Rust code.
- cargo-wasi: Supports building and running for WASI.
3.2.3. AssemblyScript
AssemblyScript is a syntax subset of TypeScript designed to be natively compiled into WebAssembly.
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ AssemblyScript โ โ โ asc Compiler โ โ โ WebAssembly โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
AssemblyScript serves as an entry point to low-level programming for JavaScript developers in the Web environment, featuring:
- Static type system and TypeScript-compatible syntax.
- Manual memory management (automatic garbage collection is also an option).
- Generation of small, optimized WebAssembly binaries.
- Easy use in browser and Node.js environments.
3.2.4. Other Major Languages
| Language | Toolchain | Maturity | Features |
|---|---|---|---|
| Go | go wasm | Good | Supported by standard build tools; binary size is somewhat large. |
| C#/.NET | Blazor WebAssembly | Good | Includes full runtime or minimal AOT mode. |
| Kotlin | Kotlin/Wasm | Early Stage | Experimental target; compiles directly without JVM. |
| Swift | SwiftWasm | Developing | Enables direct compilation to WebAssembly. |
| Python | Pyodide | Developing | Compiles the Python interpreter itself into Wasm. |
| Ruby | ruby.wasm | Developing | Compiles the Ruby interpreter into Wasm. |
3.3. WebAssembly-Specific Optimizations and Constraints
WebAssembly compilers perform special optimizations tailored to the characteristics of the target platform.
3.3.1. Adaptation to the Memory Model
| Optimization | Description |
|---|---|
| Memory Layout Optimization | Optimizes data placement within linear memory to improve cache efficiency. |
| Pointer Size Adjustment | Optimizes pointer sizes for the 32-bit address space. |
| Alignment Consideration | Adjusts data alignment to improve memory access efficiency. |
3.3.2. Code Generation and Optimization
| Optimization | Description |
|---|---|
| Instruction Selection | Efficiently maps code to the limited WebAssembly instruction set. |
| Reduction of Stack Operations | Generates code that minimizes unnecessary stack operations. |
| Function Import Optimization | Reduces overhead for calling host functions. |
| Binary Size Optimization | Code compression techniques to reduce transfer size. |
3.4. Bridging the Gap between Language Features and WebAssembly
There are several gaps between the features of high-level languages and the current feature set of WebAssembly. Compilers employ various strategies to bridge these gaps.
| Language Feature | Implementation in WebAssembly |
|---|---|
| Garbage Collection | โข Implementation via language runtime (e.g., Blazor, Pyodide) โข Reference counting (AssemblyScript) โข *Note: Adoption of the WebAssembly GC extension is in progress. |
| Exception Handling | โข Explicit error code returns โข Emulation (converting try/catch into if/goto logic) โข *Note: Adoption of the WebAssembly Exception Handling extension is in progress. |
| Dynamic Typing | โข Explicit management of runtime type information โข Generation of branching code for each type |
| Threads | โข Execution on the main thread only (limited) โข Parallelism via Web Workers + SharedArrayBuffer โข *Note: Adoption of WebAssembly Threads is in progress. |
As the WebAssembly standard evolves, these gaps are gradually being resolved. In particular, the GC extension and exception handling have already been implemented in some browsers.

4. Execution Model of WebAssembly
4.1. Stack-Based Virtual Machine
WebAssembly is designed as a low-level binary instruction format (bytecode) for a stack-based virtual machine. It processes data by temporarily holding operands (the data being operated on) and results in a memory area called the evaluation stack, rather than using registers.
4.1.1. Basic Operation of Instructions
Many WebAssembly instructions perform one of the following actions:
-
Pushing a value onto the stack (e.g.,
i32.const 10) -
Popping values from the stack, performing an operation, and pushing the result back onto the stack (e.g.,
i32.add) - Accessing memory using values on the stack (e.g.,
i32.load,i32.store)
4.1.2. Execution Flow Example
Let's look at a simple addition example.
i32.const 10 ;; Push value 10 onto the stack โ Stack: [10]
i32.const 20 ;; Push value 20 onto the stack โ Stack: [10, 20]
i32.add ;; Pop two values from the stack, add them, and push the result โ Stack: [30]
This process can be visualized as follows:
4.1.3. Advantages of Stack Machines
Stack machines offer several advantages over register-based architectures:
| Advantage | Description |
|---|---|
| Instruction Simplification | Since explicit specification of operands is not required, the instruction set becomes simpler. |
| Binary Efficiency | In many cases, the binary representation of instructions is more compact. |
| Improved Portability | It is easier to port to various platforms because it does not depend on the hardware's register configuration. |
| Ease of Implementation | VM implementation is relatively simple, and verification is easier to perform. |
4.1.4. Actual Execution Efficiency
While stack machines are conceptually simple, they are typically converted internally to register-based code for high-performance execution. In modern WASM implementations, a Just-In-Time (JIT) compiler converts WASM stack operations into efficient register-based native code, achieving high performance.
4.2. Verification Process
WebAssembly modules undergo rigorous verification before execution. This verification process is a crucial element in ensuring the safety and determinism of WASM. Verification is performed through a declarative type system to confirm that the module is "well-formed."
4.2.1. Verification Context
Verification is always performed against a "context." The context includes the following information:
| Context Element | Description |
|---|---|
| Type Definitions | List of types defined within the module |
| Functions | List of functions represented by function types |
| Tables | List of tables represented by table types |
| Memories | List of memories represented by memory types |
| Global Variables | List of global variables represented by global types |
| Element Segments | List of element segments represented by element types |
| Data Segments | List of data segments |
| Local Variables | List of local variables (including parameters) within the current function |
| Labels | Stack of labels accessible from the current code |
| Return Types | Return type of the current function |
| References | List of function indices originating outside the function and referenceable within it |
4.2.2. Structural and Type Verification
WASM verification performs strict validation of structure and stack types.
| Verification Category | Verification Item | Content |
|---|---|---|
| Structural Verification | Format Verification | Binary structure of the module (magic number, version, section structure, etc.) |
| Section Verification | Validity of the order and internal structure of each section | |
| Integrity Verification | Integrity of internal references (e.g., matching between the Function Section and Code Section) | |
| Type Verification | Stack Type Verification | Verifying the types of stack operations in the format [t1* โ t2*]
|
| Polymorphism Support | Proper type inference for parametric and stack-polymorphic (control) instructions | |
| Function Signature Verification | Type matching of parameters and return values for function calls | |
| Memory Access Verification | Validity of alignment and range for memory access instructions (load/store) | |
| Control Flow Verification | Ensuring that blocks, loops, and branches are type-safe |
4.2.3. Verification Rules for Instructions and Modules
Verification follows clearly defined rules.
| Verification Target | Verification Rule | Description |
|---|---|---|
| Instruction Sequence | Cumulative Effect Type Verification | Checking if the chain of instructions is type-safe as a whole |
| Stack Matching Verification | Matching the output type of the previous instruction with the input type of the next | |
| Module Components | Function Body Verification | Whether the expression in the function body matches its type signature |
| Table/Memory Verification | Whether they are within appropriate limits | |
| Global Definition Verification | Whether the initialization expression is a constant expression and matches the declared type | |
| Import/Export Verification | Consistency of external types and subtyping requirements |
4.2.4. Verification Results and Safety Guarantees
Modules that fail verification are not executed and are rejected immediately.
When verification succeeds, the following safety guarantees are ensured:
-
Type Safety
Prevents runtime type errors. -
Memory Safety
Prevents unauthorized memory access. -
Control Flow Integrity
Ensures proper stack states are always maintained. -
Module Isolation
Only explicitly exported functions are available externally.
Verification is deterministic and completes in a single pass. This rigorous verification system allows WebAssembly to provide a secure execution environment, eliminating runtime errors and security vulnerabilities in advance.
4.3. Memory Model
WebAssembly adopts a simple and efficient linear memory model.
4.3.1. Concept of Linear Memory
| Feature | Description |
|---|---|
| Structure | A continuous byte array (similar to JavaScript's ArrayBuffer), accessed by indices starting from 0. |
| Operation Method | Reading and writing memory via explicit load/store instructions. |
| Unit | Memory is managed in 64KiB "pages" and can be expanded using the memory.grow instruction. |
| Address Space | Currently primarily a 32-bit address space (up to 4GiB), with a 64-bit extension also under development. |
4.3.2. Guarantees of Memory Safety
WebAssembly introduces several mechanisms to ensure memory safety. These prevent buffer overflows and unauthorized memory access.
| Safety Mechanism | Description |
|---|---|
| Sandboxing | Each WASM module can only operate within its own memory space. |
| Bounds Checking | All memory accesses are forced to be within valid ranges. |
| Alignment Requirements | Memory access is guaranteed to have proper byte alignment. |
4.3.3. Integration between Memory and the Host Environment
A WASM module's memory can be shared with the host environment (such as JavaScript), enabling efficient data transfer. For example, JavaScript can directly access WASM memory through the WebAssembly.Memory object.
4.3.4. Representative Memory Operation Instructions
Here are some representative memory operation instructions as described in the WebAssembly documentation on MDN:
i32.load ;; Read a 32-bit integer value from memory
i32.store ;; Write a 32-bit integer value to memory
memory.size ;; Get the current memory size in pages
memory.grow ;; Expand memory by a specified number of pages
memory.copy ;; Copy a specific range of memory to another range
memory.fill ;; Fill a specific range of memory with a specified value
4.4. Function Calling Mechanism
WebAssembly supports multiple function calling methods to accommodate various programming paradigms and optimization needs.
4.4.1. Comparison of Calling Methods
| Calling Method | Description | Use Case |
|---|---|---|
|
Direct Call ( call) |
Function call using a static index. | Standard function calls where high-speed execution is required. |
|
Indirect Call ( call_indirect) |
Dynamic function call via a table index. | Function pointers, virtual methods, dynamic dispatch. |
| Import Function Call | Calling a function provided by the host environment. | System APIs, I/O operations, coordination with the host environment. |
4.4.2. Type Checking and Safety
Even with indirect calls, strict type checking is performed against the function signature (parameter and return types). This prevents bugs and security issues caused by function pointer type mismatches that often occur in languages like C/C++.
4.5. Runtime Optimization Techniques
Modern WebAssembly implementations employ various optimization techniques to achieve high performance.
4.5.1. Compilation Strategies
The following compilation strategies are used during WebAssembly execution:
| Strategy | Characteristics | Benefits |
|---|---|---|
| Interpreter Execution | Interprets and executes bytecode instruction by instruction. | Fast startup, low memory usage. |
| Baseline JIT | Quickly converts to native code with minimal optimization. | Early execution start with reasonable performance. |
| Optimizing JIT | Aggressive optimization based on runtime profiling. | High performance during long-running execution. |
| AOT Compilation | Completely converts to native code before execution. | Maximum execution speed at runtime. |
Many implementations use tiered compilation, combining these strategies to balance startup speed and execution performance.
4.5.2. Major Optimization Techniques
The following techniques are used for runtime optimization of WebAssembly:
| Optimization Technique | Description |
|---|---|
| Inlining | Embeds small functions directly into the caller to reduce function call overhead. |
| Loop Optimization | Enhances loop iterations (loop-invariant code motion, loop unrolling, etc.). |
| SIMD Utilization | Parallel data processing using vector instructions (using the v128 type). |
| Register Allocation | Efficient use of registers to minimize stack operations. |
| Code Specialization | Generation of specialized code paths under specific conditions. |
4.6. Internal Structure of WASM VM
The interior of a WebAssembly virtual machine consists of several collaborating components.
4.6.1. Key Components
| Component | Role |
|---|---|
| Parser | Analyzes the binary WASM module and converts it into an internal representation. |
| Validation Engine | Verifies the structure and type safety of the module. |
| Compiler | Converts WASM code into native code (JIT or AOT). |
| Interpreter | Directly executes bytecode (in some implementations). |
| Memory Manager | Manages linear memory and boundary checks. |
| Execution Engine | Executes and optimizes compiled code. |
4.6.2. Execution Flow
Execution of a WebAssembly module proceeds through a series of steps:
- Loading and Parsing: Reads the WASM binary and analyzes its internal structure.
- Validation: Confirms the safety and integrity of the module.
- Instantiation: Initializes resources such as memory, tables, and global variables.
- Compilation: Converts functions into native code (as needed in the case of JIT).
- Execution: Executes exported functions or the start function.
- Optimization: Re-optimizes code based on runtime information (in the case of tiered JIT).
4.6.3. Overall Flow
Based on the content so far, the following visualizes the internal execution process of a WASM VM. While some parts may lack absolute precision, use it as a reference to understand the general flow.

5. WebAssembly System Interface (WASI)
5.1. Overview and Purpose of WASI
WebAssembly System Interface (WASI) is a standardized system interface that allows WebAssembly modules to securely access operating system features (such as file systems, networks, clocks, and random number generation).
5.1.1. Major Design Goals
| Design Goal | Description |
|---|---|
| Portability | Provides a platform-independent API so that WebAssembly code operates consistently across various environments. |
| Security | Restricts access to only explicitly permitted resources through a "Capability-based Security" model. |
| POSIX-like | Provides a POSIX-like API to facilitate the porting of existing applications written in C/C++, etc. |
| Modularity | Logically separates functions into modules, allowing implementation and usage of only necessary features. |
5.1.2. Positioning of WASI
WASI is not part of the core WebAssembly specification, but rather a standard external interface implemented using WebAssembly's import/export mechanism. This provides the foundation for effectively utilizing WebAssembly in environments outside the browser.
+----------------------------------+
| Application |
+----------------------------------+
โ
+----------------------------------+
| WASM Module |
+----------------------------------+
โ
+----------------------------------+
| |
| WASM Runtime |
| (with/without WASI API) | โ Basic WebAssembly execution functions
| | โ + Optional standardized access to
| | OS resources (WASI)
+----------------------------------+
โ
+----------------------------------+
| Operating System |
+----------------------------------+
5.2. Relationship between WASM and WASI
To summarize once more, WebAssembly and WASI play distinct yet complementary roles:
-
WebAssembly (WASM)
Provides a binary format for safe and efficient code execution. -
WASI
Provides a standardized interface for WebAssembly code to access external system resources (primarily OS functions).
Not all WASM modules require WASI. Modules specialized for pure computation (e.g., math libraries) or for environments that have their own APIs (e.g., DOM API in a Web browser) may not use WASI.
5.3. Module Structure of WASI
WASI is designed not as a single monolithic API, but as a group of modules divided by functionality. This allows implementers to support only the necessary features and enables the specification to evolve incrementally.
5.3.1. WASI API Versions
WASI manages versions and introduces functional modules in stages. Below are the major versions of the WASI API and their status:
| Version | Standardization Status | Description |
|---|---|---|
|
WASI 0.1 (wasi_snapshot_preview1) |
Widely Adopted | The first generation WASI API. Defined in WITX format, it supports basic file I/O, environment variables, time, etc. Implemented in many runtimes. |
|
WASI 0.2 (Preview 2) |
Stable Version Released | The next-generation WASI based on the Component Model, defined in WIT format. Officially released in February 2024, it includes major APIs (Clocks, Random, Filesystem, Sockets, CLI, HTTP). |
5.3.2. Functional Modules
WASI provides modules divided by functionality. This allows applications requiring specific features to import and use only those modules.
Here are some of the major modules:
| Module | Standardization Status | Function |
|---|---|---|
| wasi-clocks | Phase 3 | Time acquisition and measurement |
| wasi-random | Phase 3 | Cryptographically secure random number generation |
| wasi-filesystem | Phase 3 | File and directory operations |
| wasi-sockets | Phase 3 | Network socket communication |
| wasi-cli | Phase 3 | Standard I/O, arguments, environment variables |
| wasi-http | Phase 3 | HTTP client and server functionality |
| wasi-nn | Phase 2 | Neural network inference |
| wasi-crypto | Phase 1 | Encryption and signature functions |
| wasi-threads | Phase 1 | Multi-threading |
*As of 2025.4
5.4. Major WASI API Features
Here we introduce the major APIs provided by wasi_snapshot_preview1, which is currently widely used.
5.4.1. File System Operations
5.4.1. File System Operations
WASI provides APIs for accessing the file system. This allows WebAssembly modules to read from and write to the host environment's file system, providing a POSIX-like interface.
Below are examples of major file system APIs:
| API | Function |
|---|---|
fd_read() |
Read from a file |
fd_write() |
Write to a file |
path_open() |
Open a file |
fd_readdir() |
Enumerate directory contents |
4.5.2. System Information and Control
WASI also provides APIs for system information and control. This allows WebAssembly modules to acquire information from or control the host environment.
Below are examples of major system information APIs:
| API | Function |
|---|---|
clock_time_get() |
Get current time |
random_get() |
Generate random numbers |
environ_get() |
Get environment variables |
args_get() |
Get command line arguments |
proc_exit() |
Exit the program |
5.5. Capability-based Security Model
One of the most important characteristics of WASI is its adoption of "Capability-based Security". This approach is fundamentally different from the "Access Control List (ACL)" model used in traditional operating systems and provides stronger security control.
5.5.1. Basic Principle
"You cannot access it unless you possess the capability."
In a WASI environment, a WebAssembly module can only access resources for which it has been explicitly granted a "capability" (access right). This directly implements the "Principle of Least Privilege," ensuring that a program can only access what it needs to function.
5.5.2. Types of Capabilities in WASI
WASI implements two different types of capabilities:
-
Handle-based Capabilities
These are dynamic references to specific resources that can be passed between components at runtime. They are "unforgeable," meaning a component cannot arbitrarily create or guess a valid handle. -
Link-time Capabilities
A link-time capability is a permission to access a "global functionality." These represent permission for system-wide features (e.g., clocks, random number generators, environment variables) rather than individual resources. They do not require a handle (identifier) because the resource being operated on is either "unique" or "does not need to be distinguished individually."
| Handle-based | Link-time |
|---|---|
| Operation of individual resources, such as "which file to read" | Access to global features, such as "obtaining the current time" |
| Necessary to handle multiple resources individually | Handles only a single service or function |
| Permissions can be controlled for each specific resource | Permissions for the entire feature are controlled collectively |
| Files, network connections, devices, etc. | Clocks, random number generation, environment variables, system info, etc. |
5.5.3. Comparison with the Traditional ACL Model
To understand the fundamental difference between the two models, let's compare the traditional ACL (Access Control List) model with WASI's capability model. This difference reflects a philosophical divergence in security approach rather than just a technical implementation detail.
The ACL model controls access based on identity ("Who are you?"), whereas the capability model controls access based on possession ("What do you have?"). This fundamental difference impacts many aspects, including how permissions are managed, the level of security guarantees, and how programs are structured.
| Feature | Traditional ACL Model | WASI Capability Model |
|---|---|---|
| Basic Unit of Access | Identity of user or group | The resource reference (handle) itself |
| Access Decision Factor | "Who are you?" (Identity-based) | "What do you possess?" (Capability-based) |
| Capability Types | Single permission model | Handle-based (dynamic resource ref) and Link-time (compile-time function ref) |
| Inheritance of Permissions | Automatically inherited based on User/Group ID | Only explicitly passed capabilities can be used |
| Delegation of Permissions | Primarily centralized management by administrators | Programs can delegate permissions to third parties with fine-grained control |
| Default State | Often a permissive model where restrictions are added | Restrictive by default; permissions must be explicitly granted |
| Security Guarantee | Depends on the correct configuration of access control lists | Accessing unauthorized resources is structurally impossible |
5.6. WASI Implementation and Ecosystem
5.6.1. Major WASI Runtimes
| Runtime | Developer | Features |
|---|---|---|
| Wasmtime | Bytecode Alliance | The reference implementation. A high-performance runtime using the Cranelift compiler. |
| Wasmer | Wasmer, Inc. | Supports multiple languages and compiler backends; embeddable. |
| WasmEdge | CNCF | Optimized for cloud-native environments; features AI/ML extensions. |
| WAMR | ByteCodeAlliance, Intel, etc. | A lightweight runtime for embedded and IoT devices. |
5.6.2. Language Support
WASI is supported by many programming languages, though the level of support varies.
| Language | Support Level | Toolchain |
|---|---|---|
| C/C++ | Excellent | WASI-SDK, Emscripten |
| Rust | Excellent |
wasm32-wasi target |
| AssemblyScript | Good | Standard build pipeline |
| Go | Partial | TinyGo |
| Others | Developing | Kotlin/Native, Swift, .NET, etc. |
5.7. Relationship between WASI and WIT
The relationship between WIT (WebAssembly Interface Type) and WASI (WebAssembly System Interface) is similar to the relationship between a language and a library. WIT is the "language," and WASI is one of the "libraries" written in that language.
5.7.1. WIT: Interface Definition Language for WebAssembly
WIT is a general-purpose Interface Definition Language (IDL) designed to describe contracts between WebAssembly components. WIT has the following characteristics:
- Clearly defines the "contract" between WebAssembly components.
- Specifies how to pass complex types such as strings, lists, and records.
- Describes function signatures, type definitions, and resource handling.
- Provides language-independent commonality.
WIT is a versatile tool capable of defining any kind of interface and is not limited to system functions. For instance, graphics libraries, database clients, and game engine APIs can all be described using WIT.
// Example of a graphics library (original API, not WASI)
interface graphics {
record point { x: f32, y: f32 }
resource canvas {
constructor(width: u32, height: u32);
draw-line: func(from: point, to: point, color: string);
fill-rect: func(x: f32, y: f32, width: f32, height: f32, color: string);
}
}
5.7.2. WASI: System Interface Described in WIT
WASI is the standard interface for WebAssembly programs to access host system features (file system, network, time, etc.).
- WASI is currently defined using WIT (from Preview 2 onwards).
- WASI can be thought of as a kind of "standard library" written in WIT.
- It defines system-level features like file systems, networking, and environment variables.
Simply put, WIT provides the method of "how to define," and WASI provides the content of "what to define." While WASI is a major application of WIT, WIT's use cases extend far beyond it.
In the WebAssembly ecosystem, it is common for developers to define their own libraries and frameworks using WIT in addition to WASI. This enables seamless interoperability between components written in different languages. WIT serves as the "common language" of WebAssembly, acting as the foundation for the entire Component Model.

6. Low-level Optimization Techniques in WebAssembly
6.1. Binary Size and Load Time Optimization
The WebAssembly ecosystem provides optimization techniques focused on efficiency from network transfer to instantiation.
| Optimization Technique | Description |
|---|---|
| LEB128 Encoding | Variable-length integer representation. Small values are represented with fewer bytes, and it is also efficient for large values. |
| Section Structure Optimization | Removal of unused sections and consolidation of duplicate code. |
| Instruction Encoding | Short opcodes are assigned to frequently used instructions, and immediate values are efficiently encoded using LEB128. |
| Binaryen Optimization | Advanced static analysis and transformation using the wasm-opt tool. |
6.2. WebAssembly-specific Code Optimization
In addition to traditional compiler optimizations, there are optimization techniques that leverage the specific constraints and opportunities of WebAssembly.
| Optimization Technique | Description |
|---|---|
| Stack Fusion | Reduces sequences of stack operation instructions and replaces them with direct register operations. |
| Function Inlining | Embeds small functions into the call site to reduce function call overhead. |
| Memory Access Pattern Improvement | Optimization of data layout considering the characteristics of linear memory. |
| SIMD Auto-vectorization | Converts scalar operations into SIMD instructions (v128) for parallel processing. |
| Table Indirect Call Optimization | Enhances table indexing efficiency using type information. |
6.3. Runtime Optimization Techniques
WebAssembly runtimes apply various runtime optimizations to improve performance.
| Runtime | Key Optimization Techniques | Features |
|---|---|---|
| V8 (Chrome) | Tiered compilation Speculative optimization Inlining Type feedback |
Multi-stage optimization via the TurboFan compiler. Dynamic re-optimization based on execution patterns. |
| SpiderMonkey (Firefox) | Baseline JIT Ion optimizing compiler Type inference |
Two-stage JIT strategy. WebAssembly-specific optimization passes. |
| Wasmtime | Cranelift code generation Alias analysis Architecture-specific |
Optimized for server-side usage. AOT compilation options. |
6.4. Optimization Strategies by Use Case
Since WebAssembly supports diverse use cases, optimization strategies vary depending on the specific scenario.
| Use Case | Optimization Priorities | Recommended Techniques |
|---|---|---|
| Web Applications | Load time, initial execution speed | Size optimization, lazy compilation, code splitting. |
| Games / Media Processing | Execution speed, consistent frame rate | SIMD, loop optimization, memory layout adjustment. |
| Edge Computing | Startup time, memory footprint | AOT compilation, size optimization, asynchronous initialization. |
| Data Analysis / AI | Throughput, memory access efficiency | SIMD, parallel processing, special instruction optimization. |

7. Latest Trends and Future Outlook of WebAssembly
7.1. Evolution of the WebAssembly Specification
WebAssembly is continuously being extended, and many important features are in various stages of standardization.
| Feature Extension | Description |
|---|---|
| Garbage Collection (GC) | Introduces reference types and GC-managed types. Enables efficient compilation for GC languages such as Java, Kotlin, and C#. Includes significant extensions to the type system. |
| Exception Handling | A structured exception handling mechanism. Supports efficient mapping to language try/catch syntax and stack unwinding. |
| Threading | Shared memory and atomic operations are already available. Standard APIs for thread creation and management are also under development. |
| Multiple Memories | Supports multiple memory instances. Allows for increased flexibility in memory usage and efficient manipulation of large-scale data. |
| Tail Call | Optimization for tail calls. Supports functional languages and recursive processing that does not consume stack space. |
| Memory64 | 64-bit memory address space. Supports large memory operations exceeding 4GB. |
Many features are already being implemented in major browsers, and the use cases for WebAssembly are expanding rapidly.
7.2. WebAssembly Component Model
The WebAssembly Component Model is a new architecture for achieving interoperability between modules, with the first stable version released in late 2023.
7.2.1. Core Concepts and Dependency Structure
The WebAssembly Component Model is designed based on clearly defined dependencies. The diagram below illustrates the basic structure and flow of dependencies in the component model.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WIT Definition (contract) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โ Component Implementation โ โ Host Implementation โ
โ (Provider/Exporter) โ โ (Consumer/Importer) โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โ Binding Code โ โ Binding Code โ
โ (Component Side) โ โ (Host Side) โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โ Wasm Binary โ โ Component Loading โ
โ (.wasm file) โโโโโโโโโถโ & Execution Code โ
โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
This structure consists of the following key elements:
-
WIT Definition (Contract)
This is a crucial element that serves as the starting point for all dependencies. WIT (WebAssembly Interface Type) is a language-independent interface definition language that functions as a contract between components. This allows for consistent communication even between different languages. -
Component Implementation Side and Host Implementation Side
Based on the WIT definition, the implementation is divided into two sides. The component side provides functionality (exports), and the host side consumes it (imports). Both share the same WIT definition but can be implemented in different languages. -
Binding Code
Code automatically generated from the WIT definition that handles the conversion between high-level language types and low-level WebAssembly representations. Component-side bindings provide export functionality, while host-side bindings handle imports and instantiation. -
Wasm Binary and Host Execution Code
Ultimately, the component-side implementation is compiled into a WebAssembly binary (.wasm file), which is then loaded and executed by the host-side execution code. At this point, the binding code mediates communication between the two.
7.2.2. Benefits
-
Interoperability Between Languages
Seamlessly integrate code written in different programming languages. -
Modularity
Split complex applications into components that can be developed and updated independently. -
Ecosystem Revitalization
Promotes the formation of an ecosystem of reusable libraries and components. -
Improved Portability
Standardized interfaces improve the portability of components.
7.3. Application to Cloud-Native and Edge Computing
WebAssembly is rapidly becoming widespread in the cloud-native and edge computing fields.
7.3.1. Actual Adoption Examples
| Product | Category | Description |
|---|---|---|
| Fermyon Spin | Serverless | A serverless application framework based on WebAssembly. |
| Cloudflare Workers | Edge Computing | A platform that executes Wasm code at CDN edges worldwide. |
| Istio/Envoy | Service Mesh | Uses Wasm as an extension for proxies (WebAssembly for Proxies/WASM). |
| WasmEdge | Runtime | A Wasm runtime optimized for cloud-native environments (under the CNCF). |
| Fastly Compute@Edge | Edge Computing | A low-latency edge computing platform using Wasm. |
7.3.2. Comparison between WebAssembly and Container Technology
WebAssembly and containers are both technologies that provide portable execution environments, but they have significant differences in design philosophy and application domains. While the boundaries between the two are gradually blurring with the emergence of new tools and integration approaches, each has distinct strengths.
| Aspect | WebAssembly | Containers |
|---|---|---|
| Startup Time | Milliseconds *Near-instant startup is possible. |
Seconds to tens of seconds *Depends on image size and configuration. |
| Resource Footprint | Lightweight (hundreds of KB to a few MB) *Only the runtime is needed; no OS layer required. |
Medium to Large (tens to hundreds of MB) *Includes basic OS components. |
| Security Model | Strict capability-based sandbox *Highly restricted permission model by default. |
Isolation via namespaces and cgroups *Relatively high risk of vulnerabilities due to misconfiguration. |
| Distribution Size | Very compact *Can be distributed as a single binary. |
Generally large *Distributed as layered images. |
| Language Support | Growing (C/C++, Rust, Go, .NET, Python, etc.) *Some language features have limitations. |
Extensive (virtually all languages) *Supports full native functionality. |
| Ecosystem Maturity | Developing *Tools, frameworks, and libraries are increasing. |
Very mature *Extensive tools, orchestration, and monitoring solutions. |
| Performance Characteristics | Near-native speed *Uses optimized JIT compilation. |
Near-native *Slight containerization overhead. |
| Application Domain | Serverless functions, edge computing, plugins, browser applications. | Microservices, legacy applications, complex application stacks. |
| Relationship with OS | OS-independent abstraction *The same binary runs on multiple platforms. |
Shared underlying OS kernel *Requires compatibility with the host OS. |
7.4. New Application Fields
The application fields for WebAssembly are expanding rapidly.
| Application Field | Example | Features |
|---|---|---|
| Game Development | Unity WebGL Export | Executing games developed in C#/C++ on the Web. |
| Plugin Systems | Shopify Functions | Safely executing custom logic on an e-commerce platform. |
| IoT / Embedded | WAMR (WebAssembly Micro Runtime) | Secure code execution on constrained devices. |
| Blockchain | Ethereum | Execution environment for smart contracts. |
| AI Model Execution | wasm-onnx, wasi-nn | Inference execution on edge devices. |
| Desktop Apps | Tauri | Lightweight apps combining Wasm and native code. |

8. Summary
WebAssembly and WASI continue to evolve as critical foundations of modern computing. A comprehensive understanding of these technologies, from their low-level operating principles to high-level applications, is indispensable for shaping the future of software development.
WebAssembly is a multi-platform virtual machine instruction format with the following key characteristics:
- Stack-based execution model
- Safety through static typing and rigorous verification
- High-speed binary encoding and execution speed
- Language-independent format
- Sandboxed memory model
WASI is a standardized system interface for utilizing WebAssembly in a wider range of environments, extending beyond the web browser.
- Capability-based security model
- Design focused on portability
- POSIX-like standard system functions
- Modularized API structure
The adoption of these technologies is progressing in diverse areas such as:
- High-performance applications in the Web frontend
- Cloud-native services and microservices
- Edge computing and IoT
- Secure plugin systems
- Cross-platform applications
WebAssembly and WASI will continue to evolve with new features such as garbage collection, threads, exception handling, and the component model. These advancements aim to enhance interoperability between languages, support more diverse application scenarios, and improve the developer experience.

Discussion