Wasm/k: Delimited Continuations for WebAssembly
by Donald Pinckney, Arjun Guha, Yuriy Brun
Abstract:
WebAssembly is designed to be an alternative to JavaScript that is a safe, portable, and efficient compilation target for a variety of languages. The performance of high-level languages depends not only on the underlying performance of WebAssembly, but also on the quality of the generated WebAssembly code. In this paper, we identify several features of high-level languages that current approaches can only compile to WebAssembly by generating complex and inefficient code. We argue that these problems could be addressed if WebAssembly natively supported first-class continuations. We then present Wasm/k, which extends WebAssembly with delimited continuations. Wasm/k introduces no new value types, and thus does not require significant changes to the WebAssembly type system (validation). Wasm/k is safe, even in the presence of foreign function calls (e.g., to and from JavaScript). Finally, Wasm/k is amenable to efficient implementation: we implement Wasm/k as a local change to Wasmtime, an existing WebAssembly JIT. We evaluate Wasm/k by implementing C/k, which adds delimited continuations to C/C++. C/k uses Emscripten and its implementation serves as a case study on how to use Wasm/k in a compiler that targets WebAssembly. We present several case studies using C/k, and show that on implementing green threads, it can outperform the state-of-the-art approach Asyncify with an 18% improvement in performance and a 30% improvement in code size.
Citation:
Donald Pinckney, Arjun Guha, and Yuriy Brun, Wasm/k: Delimited Continuations for WebAssembly, Conditionally accepted to the Proceedings of the Dynamic Languages Symposium, November 2020.
Bibtex:
@article{Pinckney20dls,
  author = {Donald Pinckney and Arjun Guha and Yuriy Brun},
  title =
  {\href{http://people.cs.umass.edu/brun/pubs/pubs/Pinckney20dls.pdf}{Wasm/k: {Delimited} Continuations for WebAssembly}},
  journal = {Conditionally accepted to the Proceedings of the Dynamic Languages Symposium},
  venue = {DLS},
  address = {Chicago, IL, USA},
  month = {November},
  date = {15--20},
  year = {2020},


  abstract = {WebAssembly is designed to be an alternative to JavaScript that
  is a safe, portable, and efficient compilation target for a variety of
  languages. The performance of high-level languages depends not only on the
  underlying performance of WebAssembly, but also on the quality of the
  generated WebAssembly code. In this paper, we identify several features of
  high-level languages that current approaches can only compile to
  WebAssembly by generating complex and inefficient code. We argue that these
  problems could be addressed if WebAssembly natively supported first-class
  continuations. We then present Wasm/k, which extends WebAssembly with
  delimited continuations. Wasm/k introduces no new value types, and thus
  does not require significant changes to the WebAssembly type system
  (validation). Wasm/k is safe, even in the presence of foreign function
  calls (e.g., to and from JavaScript). Finally, Wasm/k is amenable to
  efficient implementation: we implement Wasm/k as a local change to
  Wasmtime, an existing WebAssembly JIT. We evaluate Wasm/k by implementing
  C/k, which adds delimited continuations to C/C++. C/k uses Emscripten and
  its implementation serves as a case study on how to use Wasm/k in a
  compiler that targets WebAssembly. We present several case studies using
  C/k, and show that on implementing green threads, it can outperform the
  state-of-the-art approach Asyncify with an 18% improvement in performance
  and a 30% improvement in code size.},
}