WebAssembly is a new, cross-browser format for programs on the Web. You can read all about it in Lin Clark‘s six-part series, A cartoon intro to WebAssembly. Unlike JavaScript, WebAssembly is a binary format, which means developers need new tools to help understand and experiment with WebAssembly. One such tool is Mozilla’s WebAssembly Explorer.
The video below demonstrates the basic functions of the WebAssembly Explorer, which lets developers type in simple C or C++ programs and compile them to WebAssembly.
One advantage of WebAssembly—and of the WebAssembly Explorer—is that developers can see exactly what optimizations are being applied to their code. For example, the WebAssembly compiler in the video is able to use C’s type information to automatically select between traditional division and a more efficient bit-shifting shortcut. With JavaScript, a browser’s JIT compiler may eventually arrive at the same optimization, but there are no guarantees. Ahead-of-time compilation also avoids the profiling and observational overhead associated with opportunistic JIT compilers.
While the WebAssembly Explorer is a great learning tool, it’s still in early development and not yet suitable for complex programs. Developers who need a production-grade compiler suite should look to Emscripten, which was originally written to output asm.js but has now been extended to produce WebAssembly as well.
You can find the WebAssembly Explorer’s source code on GitHub, and you can begin experimenting with WebAssembly when it lands in Firefox 52 later this week.
About Dan Callahan
Engineer with Mozilla Developer Relations, former Mozilla Persona developer.
5 comments