Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 9 min read How-to hardMaster

Contributing support for a Wasm instruction to Winch

Adding a WebAssembly instruction to Winch, Wasmtime's baseline non-optimizing compiler, touches several layers: the wasmparser VisitOperator visitor, the CodeGenContext that manages the value stack, register allocation and spilling, an ISA-independent MacroAssembler, and an x86_64 assembler built on Cranelift's ISLE-generated instruction definitions. The i32.clz example shows how the MacroAssembler emits lzcnt when the CPU supports it and otherwise falls back to a bsr/setne sequence. Changes are tested in two ways: filetests check the emitted machine code without running it, so they work on AArch64 Macs, and differential fuzzing on x86_64 hardware compares Winch's results against another Wasm engine.

Assumes: WebAssembly stack machine basicsx86_64 assemblyRustregister allocation basics

Related posts

  • Speculative Optimizations for WebAssembly using Deopts and Inlining

    V8 hardMaster

    V8 in Chrome M137 adds speculative call_indirect inlining and deoptimization support for WebAssembly, using runtime call-target feedback gathered by the Liftoff baseline compiler so TurboFan can inline up to four likely callees behind cheap instance and target checks. When an assumption fails, the Deoptimizer serializes the optimized frame into a FrameDescription, rebuilds the matching Liftoff stack frame and resumes in baseline code mid-function. This lets the optimizer drop generic slow paths that would otherwise block further optimization. The gains matter most for WasmGC languages like Dart, Java and Kotlin: over 50% average speedup on Dart microbenchmarks and 1–8% on realistic applications, with one microbenchmark dropping from 675 ms to 90 ms.

  • Extensible Language Support in Zed - Part 1

    Zed mediumAdept

    Zed loads third-party Tree-sitter grammars as WebAssembly modules using a hybrid design. Native code consumes the parser's static parse tables after they are copied out of wasm linear memory, while only the lexing functions, including hand-written external scanners, run inside Wasmtime. This avoids depending on the user's C compiler and keeps buggy scanners from crashing the editor. It also avoids copying large syntax trees out of wasm memory on every keystroke. A new `WasmStore` API lets wasm-loaded languages behave identically to native ones, and a bundled mini-libc with a bump allocator that is reset each parse makes scanner memory leaks impossible.

  • Introducing the JetStream 3 Benchmark Suite

    WebKit hardMaster

    JetStream 3 replaces JetStream 2's separate Wasm Startup/Runtime scores with the JavaScript-style first-iteration, worst-case and average-case scoring. The old scheme broke once engines hit sub-millisecond startup that Date.now() rounded to zero, giving infinite scores. The suite also favors larger workloads over microbenchmarks. WebKit details the JavaScriptCore work behind its results. Inlining WasmGC object fields into one allocation gave about 40% on the WasmGC subtests, and removing per-object destructors gave about 40% on Dart-flute-wasm. Other work inlines bump-pointer allocation into the BBQ and OMG tiers, uses Cohen's display for constant-time subtype checks, makes priority-based non-local inlining decisions, and profiles indirect calls for guarded inlining.

  • Four Approaches to Debugging Server-side WebAssembly

    Shopify Engineering mediumAdept

    Step-debugging server-side WebAssembly can be done four ways: compiling to a native target and using LLDB/GDB, running the Wasm under Wasmtime inside LLDB, using a Wasm-specific debugger like Wasminspect, or using browser DevTools via Chrome's DWARF extension or source maps. Native compilation gives the best variable rendering and familiar tooling, and is the only option for interpreted languages, but may require stubbing imported functions and cannot reproduce Wasm-specific behavior. The other approaches suffer from lower-fidelity variable rendering, missing features, or harness setup. The recommendation is to debug natively by default and fall back to Wasmtime+LLDB or browser tools when bugs only reproduce in a Wasm engine.

  • C ABI Changes for `wasm32-unknown-unknown` | Rust Blog

    Rust Blog mediumAdept

    Rust is switching the `extern "C"` ABI on `wasm32-unknown-unknown` from a legacy non-standard definition to the WebAssembly tool-conventions C ABI, which changes generated binaries. The key difference is that the legacy ABI "splats" by-value structs into separate wasm parameters, while the standard ABI passes them indirectly through linear memory. wasm-bindgen was already fixed, but other projects still rely on the old behavior. To check exposure, build with nightly-2025-03-27 or later, watch for the new future-incompat warning (stable in 1.87.0), and test with `-Zwasm-c-abi=spec`. Affected projects can pin the compiler, adopt the spec ABI on nightly, or stop passing structs by value (e.g. pass `&Pair`) before the legacy flag is removed around summer 2025.

The quest for software engineering knowledge.

Look:
Layout: