WebAssembly Takes A Big Step Towards Being Real
Written by Ian Elliot   
Wednesday, 16 March 2016

WebAssembly will be the biggest change in web development since JavaScript was introduced and now we have proof positive that it is moving towards becoming something real. Microsoft, Google and Mozilla have all released compatible previews of WebAssembly and a game you can actually run.

JSlogo

WebAssembly was announced last year as a great revolution in the way code could be run in a browser. At the time it all seemed very vague and a long way from a practical proposition but slowly things are coming together. In theory Google, Mozilla, Microsoft and Apple are working on defining and implementing WebAssembly withing the W3C WebAssembly Community but today's announcements are notable for the absence of Apple and Webkit.

WebAssembly is now available in Chrome Canary and Firefox Nightly and in an internal build of Edge. You have to set a flag to enable WebAssembly in both Chrome and Firefox. After restarting, a new Wasm object is available in JavaScript that can instantiate and run WebAssembly modules. 

There is also a demo program showing how fast WebAssembly can run a 3D game. The game, Angry Bots, can be run in WebAssembly or using asm.js.  

WebAssembly is an Abstract Syntax Tree (AST) representation of what is essentially the asm.js subset of JavaScript. This is much easier to optimize and hence WebAssembly can run fast using a lot of the infrastruture already available within the current JavaScript engines. Essentially the ASTs are precompiled representations of asm.js which allows the engines to get on with executing the code rather than parsing the source.  According to the V8 engine blog:

"A specialized WebAssembly decoder validates modules by checking types, local variable indices, function references, return values, and control flow structure in a single pass. The decoder produces a TurboFan graph which is processed by various optimization passes and finally turned into machine code by the same backend which generates machine code for optimized JavaScript and asm.js."

You can see how the Mozilla team describes the difference between processng asm.js and WebAssembly:

 

webasm

The Mozilla blog suggests that the demo game compiles in about half the time it takes for asm.js. 

At the moment the ASTs are transferred in human readable form, but the next stage is to convert them to a compact binary format. This will make them smaller and hence load faster. 

On the game's GitHub page is also a status report:

WebAssembly Demo Status

Early multi-browser support Runs in experimental builds of Chromium, Firefox, and Edge.
Demo execution Full execution semantics implemented.
Stable binary format Binary format will be updated to match design iterations, until it is frozen for stable release.
Standard textual encoding Textual encoding will be standardized before stable release.
Stable tooling A mature toolchain for compiling and debugging WebAssembly will be available before stable release.
Stable JS API The Wasm object will be updated to allow additional behavior and introspection before stable release

 

You can see that there is still some way to go. 

What is also missing are the toolchains needed to create WebAssembly. These are under development but as the V8 blog says:

We’re also planning future WebAssembly features (including multi-threading, dynamic linking, and GC / first-class DOM integration) and continuing the development of toolchains for compiling C, C++, and other languages via the WebAssembly LLVM backend and Emscripten.

At the momement none of this is usable for production apps, but it is proof that WebAssembly is coming. There are plans to change the details of most of what is on offer at the moment. The Firefox blog suggests that the as well as the basics they plan to augment the browser devtools to include a WebAssembly debugger and profiler. 

There is some speculation about whether or not WebAssembly could be used to compile JavaScript programs. While anything in the software world is possible if you put enough effort into it this seems unlikely. The reason is that WebAssembly can be regarded as a precompiled version of asm.js which is a strict subset of JavaScript. To represent a complete JavaScript program in WebAssembly you would have to map all of JavaScript into asm.js. This might be possible but it isn't easy and it is difficult to know how fast the result would be. 

 

 webassemlogo

More Information

A WebAssembly Milestone: Experimental Support in Multiple Browsers

Experimental support for WebAssembly in V8

Github WebAssembly

From ASM.JS to WebAssembly Brendan Eich

Related Articles

Progress On WebAssembly 

WebAssembly Has Mozilla, Microsoft,Apple and Google Backing It 

Asm.js Goes All Edgy 

Support For Asm.js Growing?       

Mozilla Enhances Browser-Based Gaming       

WebKit JavaScript Goes Faster Thanks To LLVM       

Firefox Runs JavaScript Games At Native Speed  

Asm.js Gets Faster       

Java, ASM.js Or Native - Which Is Faster?       

JavaScript Assembly Language       

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin

 

Banner


Firefox 1.0 Released 20 Years Ago
10/11/2024

A news item with the headline "Firefox browser takes on Microsoft" from 20 years ago has attracted renewed attention. It was originally published on the BBC News website on November 9th, 2004 rec [ ... ]



Meta Releases OpenSource Podcast Generating Tool
28/11/2024

Meta has released an open source project that can be used to automatically convert a PDF file into a podcast. Meta says Notebook Llama can be considered an open-source version of Google's NotebookLM.

 [ ... ]


More News

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

Last Updated ( Wednesday, 16 March 2016 )