Jacob Nilsson, Andreas Trattner:
Analyzing front-end performance using Webassembly,
summary,
report, June 2022.
Abstract:
With an increasing demand for high quality web services, IKEA needs to be able to deliver new features while keeping their web services responsive. Javascript, being the programming language used in the major web browsers, runs on the vast majority of websites today to enable complex behavior. However, being a dynamic, JIT compiled language, its execution comes at the price of certain runtime overheads and best-effort optimizations. A new technology native to the web, WebAssembly, was created to address many of these shortcomings. The goal of this thesis is to evaluate the performance of Javascript in comparison to WebAssembly for common algorithms that are not domain-specific.
To accomplish this, a literature study of the two technologies was conducted. IKEAs web solutions were explored through interviews in order to identify common patterns and techniques that should be generalizable to the majority of the web. A custom benchmarking framework was created in order to analyze multiple stages of WebAssembly execution in the browser. Finally, algorithms representative of the identified common techniques were benchmarked in both Javascript and WebAssembly.
An unexpected result shows that WebAssembly is subject to significant data exchange overheads when non-primitive Javascript data is passed between the contexts. A more expected result shows that if the data exchange phases are disregarded, WebAssembly executes faster than Javascript in most circumstances, sometimes on an order of several magnitudes faster. Improvements in WebAssembly, such as using references to external data in an efficient way, could open up the technology to a broader use case.