← Back

WebAssembly & Rust

WebAssembly and Rust are changing how we build high-performance, secure, portable, and scalable software.

These past few months I have been introducing many improvements in the core of Mantra, laying the groundwork so that components in a project can include modules in WebAssembly format and programmed in Rust, without making the component lifecycle more complex. I am working on this path precisely because Mantra is designed to implement high-performance and scalable applications, due to the nature of the framework and the development paradigm it follows.

I have been diving into these technologies since the beginning of the year, and although throughout my professional career I have already seen several promises that claimed they would “change everything” (probably hiding some commercial purpose, of course), only to disappear into oblivion years later, I cannot say the same about WebAssembly in general and Rust as a language in particular.

WebAssembly
Rust

Why? I explain it below.

Software works in exactly the same way as other activities: it is true that, at times, a passing fad imposes technologies (or certain libraries or frameworks, which are not always clearly distinguished from each other) that, in my opinion, should not occupy the prominent place they have, but in other cases, the enormous usefulness of something makes its use explode because it fills a gap in the industry or solves an important problem.

That is precisely what I think of WebAssembly and Rust: like the rest of the technologies, they do not solve all problems and are not a catch-all for everything, but they have their place and their use cases.

These are mainly based on applications (increasingly in demand and on the rise) that need much higher performance (close to that of the native machines where they run) and cannot be obtained for various reasons with other programming environments, but they also add other characteristics that, honestly, have surprised me as I have delved into them: greater security due to Rust’s very nature, no need for a memory collector (yes, read that again), and, most importantly, portability across different hardware architectures and operating systems, nothing less.

While WebAssembly is a low-level language similar to assembly (relax, there is no need to go back to programming in assembly), and it generates a compact and highly portable binary format when compiled (producing wasm files) that can be run in most browsers but also in other environments, Rust is a language designed from the ground up to generate efficient code, with safe memory usage and safe thread contexts, and it resembles C and C++ a lot, although it is not as low-level as those.

Rust is not a language for any type of application, but rather, given its nature, for system programming: drivers for embedded devices, operating systems, image and video processing, internetworking, virtualization, and even programming other higher-level languages. Another definition of Rust: it is a language for concurrent programming without the difficulty that this entails in languages such as C or C++, while maintaining the performance of those languages.

To put it another way, WebAssembly packages in that portable, efficient binary code the result of applications written in Rust (but also in C and C++).

WebAssembly is strongly supported by major industry players such as Mozilla, and in my opinion, although it has already been around for a few years, its use and applications are going to expand enormously in the future: image and video processing, real-time applications handling large volumes of data, embedded applications for IoT devices, FaaS (functions as a service), gaming (since these are also applications that require higher performance), cross-platform applications, etc.

On the other hand, the learning curve for the tooling for WebAssembly and for Rust, in my opinion, is low, especially if you already have prior experience with C or C++ environments and have coded at a low level a lot. In a previous work stage, I spent 12 years programming in C++, so I see many similar features in Rust that fill me with a strange kind of nostalgia :-)

In software, technologies are often launched that end up being ephemeral (and that probably cost us many hours to learn), but WebAssembly and Rust have arrived to stay; one only has to look at which companies use them, support them, and are involved in their development.