BT

WebAssembly: A Universal Binary and Text Format for the Web

by Abel Avram on Jun 18, 2015 |

Mozilla, Google, Microsoft and Apple have decided to develop a binary format for the web. Called WebAssembly, this format could be a compilation target for any programming language, enabling applications to run in the browser or other agents.

A couple of years ago, we discussed here on InfoQ the merits of a universal bytecode for the web (see Debate: Do We Need a Universal Web Bytecode?), outlining the difficulties in creating one. The main problem mentioned was the disagreement between the major browser makers: Mozilla was pushing asm.js, Google was behind PNaCl, Apple was working on FLTJIT, while Microsoft were not showing interest in any of them. But that has changed. All four major browser vendors have agreed on creating WebAssembly or WASM/wasm, a binary format for the web. Some call this a bytecode, but wasm is not a bytecode in the traditional sense, as Brendan Eich noted: “And WebAssembly is indeed a compressed AST encoding, not a stack bytecode. Shhh, don't tell anyone. You can still call it bytecode if you like.”

The project has been in stealth mode so far, but now it has become public with a GitHub presence and a W3C Community Group. WebAssembly is meant to allow programs written in languages other than JavaScript to run in the browser and other JS agents on the server, mobile or IoT. This format will eventually replace asm.js and PNaCl. According to the project’s design documents, which are not yet definitive, WASM uses a binary because it “provides efficiency: it reduces download size and accelerates decoding, thus enabling even very large codebases to have quick startup times.” WASM has an accompanying text format that can be used by debuggers and other tools facing the developer. Tools should be able to translate from one format into the other without any loss of information.

A first temporary step in implementing WebAssembly has been made: translating the format into corresponding asm.js code so it can already run on supporting browsers: Firefox, Edge, Chrome. There is already a polyfill prototype built for this purpose, and initial results show that the gzipped binary format is 20-30% smaller than the corresponding gzipped asm.js, and that wasm decoding is about 23× faster than parsing the corresponding asm.js source. WASM will later be natively supported by the browser’ VM.

WebAssembly will first bring C/C++ programs to the web, but later it can be enhanced to support any other language. A LLVM backend and a clang port are planned. WASM will execute in the “same semantic universe as JavaScript”, will support asynchronous calls to/from JavaScript, access all the browser APIs, and comply with the same security policies JavaScript programs are subject to. A client application could be written completely in WASM or it could have the business code in WASM and the UI in HTML/CSS/JavaScript.

Announced on the heels of JavaScript’s 20th birthday and on the same day Ecma announced the final approval of ES6, WebAssembly is not good news for JavaScript: WASM will make it possible to code for the web in any language that will compile to it. JavaScript will directly compete with other languages. Should we expect to see Java or C# compiled to WASM?

WebAssembly will benefit from lessons learned developing asm.js and PNaCl, since the respective teams from Mozilla and Google are involved in creating it. Having Microsoft and Apple supporting it is very promising for the project. The only problem remaining is time: usually projects developed by multiple large corporations take a lot of time. The standardization process is slow in such cases.

Rate this Article

Relevance
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Good to see by Mike Gale

Hallelujah

Isomorphic PHP here I come! by Dio Synodinos

Isomorphic PHP here I come!

Die! JavaScript, die? :) by Hari Iyer

Perhaps this is why Google isn't pushing Dart VM for the browser anymore.

the most common sense initiative by Florin Neamtu

... in the jungle of web programming since browsers appeared on Earth, and long awaited!

So ActionScript and Applets all over again? by J B

History repeats itself it seems.... until it dies of a thousand cuts of bloat and security flaws.

Re: Die! JavaScript, die? :) by J B

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

6 Discuss
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you’re using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.