Slide 1

Slide 1 text

What If the Runtime Was Portable Too? Self-Hosted Runtime Capabilities in Wasm Yuki Nakata X:@chiku_wait Researcher / Ph.D. student SAKURA internet Inc. / Future University Hakodate, Japan

Slide 2

Slide 2 text

2 The “Portability” of Wasm 1. Language-independent 2. Hardware- and platform-independent Write once, run anywhere Compile to Wasm

Slide 3

Slide 3 text

3 The “Portability” of Wasm 1. Language-independent 2. Hardware- and platform-independent Write once, run anywhere Compile to Wasm Wasm Runtime Wasm Runtime Wasm Runtime Bytecode Bytecode Bytecode Abstract Hardware and Platform

Slide 4

Slide 4 text

4 Diversity of Wasm Runtimes • 100+ runtimes with different characteristics* • Execution model (Interpreter, JIT or AOT) • Target platforms and workloads *Yixuan Zhang, Mugeng Liu, Haoyu Wang, Yun Ma, Gang Huang, and Xuanzhe Liu. 2025. Research on WebAssembly Runtimes: A Survey. ACM Trans. Softw. Eng. Methodol. Just Accepted (January 2025). https://doi.org/10.1145/3714465 Wasmtime High performance with JIT compilation WasmEdge Rich extensions for AI/LLM workloads

Slide 5

Slide 5 text

5 Portability Limitations Imposed by Runtime Diversity WasmEdge-specific Statistics and Resource Limitation Capabilities Different Status of Wasm Feature Support • Unsupported capabilities and features impose limitations on usable runtimes How can we use or implement them runtime-neutrally?

Slide 6

Slide 6 text

6 Self-hosted Runtime for Runtime-neutral Extensions • Minimal Wasm-ised Wasm runtime • Execute app bytecode via self-hosted runtime • Compatibility layer for host runtimes • Implementing extensions to self-hosted runtime only • No need to modify host Wasm runtimes • PoC (Chiwawa U^ェ^U): https://github.com/oss-fun/chiwawa Self-hosted Runtime Host Runtime (E.g., Wasmtime) Wasm Bytecode

Slide 7

Slide 7 text

7 Use Case: Cross-runtime Checkpoint/Restore (C/R) • C/R requires to save and resume the application’s state • Needs to modify optimizations (e,g.,JIT and AOT) and runtime implementation • Self−hosted runtime−based C/R • Save states in the self-hosted runtime • No need to consider runtime differences Implemented in Chiwawa Self-hosted Runtime (JIT Compiled) Wasmtime Wasm Bytecode WasmEdge Self-hosted Runtime (Interpreted) Wasm Bytecode Checkpoint and restore

Slide 8

Slide 8 text

8 Use Case: Tracing and Instrumentation • Understand the execution status of running Wasm bytecode • For bug detection, visualization of processing flows, and profiling • Self-hosted Runtime-based instrumentation • Detailed tracing including the state of its VM • Can use any runtime without modification Implemented in Chiwawa Self-hosted Runtime (JIT Compiled) Wasmtime Wasm Bytecode in Self-hosted Runtime WasmEdge Self-hosted Runtime (Interpreted) The self-hosted runtime's VM is not changed by the host’s optimization

Slide 9

Slide 9 text

9 Use Case: Executing Runtime Unsupported Features • Execute a self-hosted runtime as a compatibility layer • Implement interfaces for unsupported features • Compile the self-hosted runtime into Wasm executable for the host runtime • Can execute it within the scope supported by the host runtime Self-hosted Runtime (Support WASIp2 Interface) Host Runtime (Support WASI p1) z Wasm Bytecode (WASIp2) Using WASIp2 Feature Executing WASIp2 features as a WASIp1 bytecode Under consideration in Chiwawa

Slide 10

Slide 10 text

10 Performance Overhead by Duplicated Runtime 1. Increase bytecode instructions executed on host runtime • An instruction in an application is transformed into multiple instructions 2. Duplicated computationally expensive processing • Sandbox mechanism and WASI implementations local.get … fn handle_local_get(ctx: Context){ … let val = ctx.frame.locals[i].clone(); ctx.value_stack.push(val); … }

Slide 11

Slide 11 text

11 Optimization Techniques for Self-hosted Runtime 1. Merging instructions • Parser identifies dependencies between instructions • Convert stack instructions to Immediate Value 2. Pass-through WASI implementation (without WASI interface conversion) • Redirect to the WASI implementation of a host runtime … i32.const 10 local.get 0 I32.add local.set 1 … … i32.add{10, local@0} => local@1 … Merged into a single instruction

Slide 12

Slide 12 text

12 Chiwawa on Wasmtime VS. Wasmtime Relative execution time (normalized to wasmtime) Performance Evaluation Wizard on Wizard VS. Chiwawa on Wizard (Self-Hostable Runtimes ) 1.3~1.4x performance by optimization techniques Benchmarks Wizard on Wizard Chiwawa on Wizard pi-Leibniz 26.791 19.620 N-body 14.554 9.932 Execution time (Sec.)

Slide 13

Slide 13 text

13 Wizard on Wizard VS. Chiwawa on Wizard (Self-Hostable Runtimes ) Benchmarks Wizard on Wizard Chiwawa on Wizard pi-Leibniz 26.791 19.620 N-body 14.554 9.932 Performance Evaluation Chiwawa on Wasmtime VS. Wasmtime 13-426x performance degradation by increased processing Relative execution time (normalized to wasmtime) Execution time (Sec.)

Slide 14

Slide 14 text

14 Conclusion • A Self-hosted runtime helps implement and test features and runtime capabilities • Can run on any runtime • Significant performance overhead • Performance optimization techniques are essential • My future goal is to achieve performance equivalent to execution in existing interpreter runtimes Chiwawa: https://github.com/oss-fun/chiwawa