Evaluating Stack Switching in WebAssembly
Compiling control-flow abstractions like light-weight threads, async/await, and generators to WebAssembly typically requires whole-program transformations that complicate compilation and impose runtime and code-size costs. WasmFX extends WebAssembly with native stack switching based on effect handlers, providing a common foundation for these features. We evaluate WasmFX backends for C, Go, Kotlin, and OCaml and implementation trade-offs in the V8, Wasmtime, and Wizard engines. We compare performance against existing compilation strategies when using these engines. On artificial microbenchmarks involving tight context-switching loops, existing techniques sometimes outperform WasmFX. However, as the stack becomes deeper, WasmFX gains a substantial advantage over Asyncify, the transformation used by our C baseline to emulate stack switching. Even with substantial scope for further optimisation, current WasmFX implementations deliver competitive performance on macrobenchmarks without requiring whole-program transformations.
Authors
- Frank Emrich (ORCID: https://orcid.org/0000-0002-8591-2740)
- Ben L. Titzer (ORCID: https://orcid.org/0000-0002-9690-2089)
- Ezra Cooper
- Thibaud Michaud
- Daniel Hillerström (ORCID: https://orcid.org/0000-0003-4730-9315)
- Andreas Rossberg (ORCID: https://orcid.org/0000-0003-3137-3160)
- Conrad Watt (ORCID: https://orcid.org/0000-0002-0596-877X)
- Sam Lindley (ORCID: https://orcid.org/0000-0002-1360-4714)
- Francis McCabe
- Jérôme Vouillon
- Aleksandr Shefer
- Amy Yin
- Carlos Amedee
- Cherry Mui
- Veronika Sirotkina
- Ricky Vetter
- Zalim Bashorov
Institutions
- Google (United States) (US)
- Nanyang Technological University (SG)
- University of Edinburgh (GB)
Publication Details
- Journal
- arXiv
- Published
- 2026-12-02
- DOI
- https://doi.org/10.48550/arxiv.2612.03634
- Primary Topic
- Logic, programming, and type systems
- Type
- preprint