I created the fastest WASM interpreter — WASMZ

Introduction

wasmz is a WebAssembly runtime written in Zig, designed to be fast, compact, and easy to embed. It implements a full-featured interpreter with support for modern WebAssembly proposals and WASI.

Benchmark

https://ray-d-song.github.io/wasmz/bench.html

I’ve also documented most of the performance optimizations done by Wasmz at the bottom of this page.

Real-World Testing

wasmz passes real-world WebAssembly module tests:

  • esbuild - JavaScript bundler compiled to WASM

  • QuickJS - Lightweight JavaScript engine compiled to WASM

  • SQLite - Database engine compiled to WASM

Motivation

Existing mainstream WASM interpreters (not heavyweights like wasmtime that include AOT and JIT, but pure interpreters) lack support for modern features (new exception and GC proposals), making it difficult to run my other project that compiles Kotlin to Wasm.

At the same time, I want to build something to verify what I’ve learned from studying Lua and Ruby source code. Wasm is a very suitable target, and Zig is a handy tool.

Initially, I tried C3 and Go, but honestly, I don’t like C3’s syntax, and they have issues with support on some niche platforms, while Go is hard to run on bare metal.

This is my first Zig program, so there are many rough parts. Sorry about that—this is also what I’ll mainly polish in the next stage.

If you find workloads where wasmz has a clear disadvantage, please let me know. I will do my best to optimize them :slight_smile:

3 Likes

Oh this is really nice. I like the wasmi crate (honestly mostly because it can be compiled to wasm itself, like it’s used in Typst) but for whatever reason it still has not implemented the GC spec. (No longer a proposal!)

I might actually use this implementation as a reference to add GC to wasmi if the architecture is close enough.

Edit: here is some of my playing around with wasmi. I might repeat this exercise with zig now.

You did the GC extensions :slight_smile: I was hoping someone would. Great project, thanks.

Welcome to Ziggit!