Major browser vendors have agreed to implement a new web standard that will bring near native performance to the web for online games, music and video streaming, AR and VR, and other applications. The result, WebAssembly, is a portable, cross-vendor, cross-language, size and load time Abstract Syntax Tree (AST) that gets stored in a binary format suitable for compilation to the web. Initially released to public in June, WebAssembly, also known as wasm, is now in the browser preview phase.
Designed for the open web, WebAssembly will make use of the same web APIs accessible from JavaScript, in the same versionless, feature-tested and backward-compatible nature.
According to Mozilla’s Luke Wagner, the new runtime will remain in preview phase until early 2017, after which a draft a draft specification of WebAssembly will follow. The runtime will be implemented in JavaScript engine of each browser including Firefox’s SpiderMonkey, Chrome’s V8, Microsoft’s Chakra, and Apple’s WebKit JavaScriptCore. Currently, WebAssembly is implemented in test-mode in Chrome and Firefox, with Microsoft developing an internal build of Edge integrated with WebAssembly.
Will WebAssembly Replace JavaScript?
JavaScript is a universal language for the web and is expected to remain that way for the foreseeable future. Wasp is designed to be implemented alongside JavaScript on a case by case basis, where JavaScript’s complex syntax it’s not feasible, essentially eliminating the parser as a bottleneck. For example, JavaScript and WebAssembly can be used together for:
- C++ (and, in the long term, other static programming languages) compiled apps that leverage JavaScript to glue things together
- HTML/CSS/JavaScript UI around a WebAssembly core canvas
- HTML/CSS/JavaScript apps with high-performance WebAssembly modules
A recommendation for a more detailed idea on why WebAssembly is more of an evolutionary step for JavaScript than a replacement can be found in Peter Bright’s great article on WebAssembly. Have a look at it here.
Do We Need WebAssembly with asm.js?
WebAssembly is being developed alongside asm.js. In fact, WebAssembly is the result of the combined creative force of the team that developed asm.js at Mozilla, and Google’s developers that worked on NACL and PNaCl, the LLVM based binary format. The main advantage of wasm is that its binary format can be decoded much faster than JavaScript can be parsed. While asm.js has proved to bring significant performance improvements, it’s still parsing JavaScript.
WebAssembly aims for a complete feature parity with asm.js. While wasp is revolutionary, the development is as an evolutionary path from the already existing paradigm. For the time being, as long as you are keeping in touch with the latest evolution of wasp, and with Google’s team developing tools that automatically convert asm.js sites to WebAssembly, it’s safe to continue compiling your code to asm.js.
How Can You Get Started with wasp?
On Chrome Canary, you can test WebAssembly by switching the chrome://flags/#enable-webassembly and enable the switch, and, on Firefox Nightly, set javascript.options.wasm to true. There is also a preview version of Microsoft Edge with support for WebAssembly. For Safari, keep an eye on WebKit’s feature status page, as support should be added soon.
One Response