Matlab is a matrix-based dynamic scientific language used by scientists and engineers worldwide. It provides easily expressible high-level matrix operations through a wide variety of builtin functions. As proprietary software, it is important to have alternative compilers and tools that will allow compilation and execution in other environments. JavaScript and its sophisticated virtual machines provides a way of easily distributing and executing code, albeit with some performance problems coming from the dynamic nature of the language. To bridge the gap in performance WebAssembly was introduced as a new binary encoding language for the Web. WebAssembly offers a typed, low-level ISA with an easily verifiable binary format and low-level operations that map easily and performantly to all major hardware architectures.
In this work, we will present a matrix library in WebAssembly, inspired by the Matlab builtins. First, we will explain our design and compiler strategies to represent Matlab constructs and builtins in WebAssembly. Secondly, we will show how our library can serve as a backend for two compilers: MatJuice, a static compiler from Matlab to JavaScript, and MatWably, a static compiler from Matlab directly to WebAssembly. In particular, we will discuss the key challenges in retargeting to a typed, low-level language such as WebAssembly. To evaluate the work so far we will present experimental results, comparing the original Matjuice (based entirely on JavaScript), with the new modified version using the WebAssembly built-ins, through a set of numerical benchmarks. Finally, we will discuss two aspects of continuing and future work. Firstly, we’d like to develop an approach to completely generalize the WebAssembly library to all number types supported by Matlab. Lastly, we would like to explore the relevant performance bottlenecks and possible optimizations that apply to this domain.