Introduction to Web Assembly
What is Web Assembly, and what is it for?
Before Web Assembly
The rise of Web Assembly
The Firefox web browser shipped support for Web Assembly in 2017, and the other browser vendors quickly followed, so that in 2019 all the major browsers now support it.
What is Web Assembly?
Web Assembly is a standard that defines a limited set of operations, together with a model for handling memory, that maps closely to hardware platforms like PCs, Macs and mobile phones. It is designed to close the gap between the web browser and native applications. Rather than the browser converting a high-level language into machine code while the program is running, the developer compiles their program into Web Assembly before it is shipped. The browser still has to convert the Web Assembly into native code for the host machine, but this is much easier since the platforms are so similar.
Programming in Web Assembly
Math.sin? You have to write your own algorithm to calculate the sine of a number. Concatenate two strings? Web Assembly doesn’t even know what a string is — it only understands numbers.
All this might seem crazy, but it’s because Web Assembly is not designed to be written by humans. It’s designed as a compilation target for other languages, and the compilation environments for those languages will provide whatever maths, string and other algorithms the language needs.
That said, look out for my next post in which, rather than compiling a program from a high-level language into Web Assembly, I code the program in Web Assembly’s own low-level assembly language.