Mechakhan Logo

Mechakhan's Domain

Webassembly Thesis Published

Posted Tue, 15 Aug 2023 08:15:42 +0200 | |

Last spring I wrote my master’s thesis about pre-initializing Webassembly binaries using the Wizer tool. It was recently published in KTH’s DiVA database.

Abstract

WebAssembly (Wasm) has emerged as a new technology for the
web that enables complex and interactive web applications,
while utilizing a compact and platform-independent bytecode
format. Due to its flexibility, portability, and built-in
security, it has since evolved to be used in many other
embeddings, such as internet-of-things, server applications,
and even mobile applications. While a goal of Wasm is near-
native performance, research has found that its performance
is not as great as initially expected. Due to this,
projects like The WebAssembly Pre-Initializer (Wizer) have
emerged as potential solutions to this problem. Wizer is a
tool developed by the coalition Bytecode Alliance with the
purpose of speeding up the startup time, or Critical Path
to Interactive (CPTI), of a Wasm module by pre-initializing
it and saving a snapshot of the Wasm instance state into a
new Wasm module. Wizer has been evaluated using two bench-
mark programs. However, no larger-scale investigation into
the CPTI improvement brought by its pre-initialization has
been conducted. Furthermore, saving a snapshot of the
module is likely to result in a larger module in terms of
file size, leading to increased compile time or, for use
cases where it is relevant, network latency. This project
investigates, mainly within the field of Wasm in non-web
environments, the extent to which Wizer is able to improve
CPTI for a Wasm module. The purpose of this is to allow
both Wasm maintainers and developers to form an opinion
whether pre-initialization could be standardized for use
in Wasm compilers and toolchains, or whether pre-
initialization should be applied to their Wasm module
based on its CPTI before pre-initialization. Results are
obtained by compiling a number of sample software down to
Wasm, measuring their CPTI in terms of elapsed CPU cycles
both without and with pre-initialization using Wizer, and
comparing them. This is made possible through an
extension to the Sightglass benchmarking framework also
developed by Bytecode Alliance. The results show that
pre-initialization using Wizer increases the CPTI if the
Wasm module cannot be compiled to native CPU instructions
in advance. However, if compilation can be done in
advance, Wizer is able to reduce the CPTI of a Wasm
module by a factor of between two to six times, depending
on how it is initialized.

As a part of it you can find my fork of the Sightglass benchmarking framework for the Wasmtime runtime here.