Until recently, JavaScript was the only language supported by all web browsers. But it was difficult to compile it efficiently and the JavaScript applications typically run much slower than native applications.
Then, programmers from the four main browser vendors designed a new language, sort of a machine code for the web, and called it WebAssembly. The new language was first announced in the “Bringing the Web up to Speed with WebAssembly” paper in 2017, a specification published together by Google, Microsoft, Mozilla, and Apple. The specification lists in detail the formal syntax and explains design choices made. A major design goal of WebAssembly has been high performance without sacrificing safety or portability. To provide security, each WebAssembly module is designed to have a single block of memory (array of bytes), disjoint from code space and other internal memory spaces. It is not possible for compiled programs to corrupt their execution environment.
This week, the “Analyzing the Performance of WebAssembly vs. Native Code” study was published, which appeared to throw cold water on claims that WebAssembly is only about 10% slower than native code. The study shows numbers that are closer to 50-90% slower. However, in order to run large suite of performance tests SPEC CPU, the authors significantly modified how WebAssembly is run in the Unix environment by adding support for a file system and I/O. It is not clear if their implementation is sound.
While discussing WebAssembly, you might be wondering about what is the level of WebAssembly support across web browsers. For this purpose, head over to CanIUse.com, a web site that details web technology support on a per-browser basis. When searching for “WebAssembly”, you get the following picture, indicating that all major browsers do support WebAssembly.
I work in CAD software development, so I read with great interest about Autodesk’s recently completed rewrite of its behemoth AutoCAD software to support web browsers by using the LLVM framework with Emscripten on the back-end to produce WebAssembly. Considering millions lines of code comprise AutoCAD, it was no small feat.
I suspect that I will come back to this topic in a future blog post here at CodingRestart. Until then, happy coding!