WebAssembly Has Backing From Mozilla, Microsoft,Apple and Google
Written by Ian Elliot   
Thursday, 18 June 2015

When the history of this era of programming is written, what happened will seem like the drunken lurchings of a lunatic. First we have JavaScript, then asm.js and now WebAssembly. Is there no planning, forethought and vision in web development? Apparently not.

The history may be crazy but WebAssembly is another small step in the right direction. The browser is the OS of the 21st century and yet it only runs one language natively - JavaScript. Say what you like about JavaScript, I happen to like it, having only one language in any environment is not good.


Of course there is nothing stopping anyone inventing a new language or taking an old language and compiling it to JavaScript so that it can run in a browser. The problem is that JavaScript is a very high level language and not really suited to its role as the assembly language of the web. This is where asm.js enters the picture a proper subset of JavaScript designed to be more like a low level language with integer and floating point data types it can be fast. That is asm.js is a much more suitable assembler for the web. 

The point is that we could at any point have simply opted to build a virtual machine into the standard web browser. It might even have been the JVM making all Java related languages instantly run-able in the browser. But despite Google's best efforts to get PNaCL a byte code interpreter accepted it has been mostly ignored. 

Instead of designing some sort of interface between the browser and any VM you care to opt for i.e. a true language ecosystem what we now have is another JavaScript compatible approach.

Web assembler (or wasm) is a binary byte code that has all of the primitive data types, integers of various sizes and floats and a range of simple operators and flow of control structures. It is binary but the byte code has such a close affinity to a text representation that you can swap between them without a loss of information. This will be good news to anyone wanting to view the code as part of the browsers source view but not so good news for any programmer sick of having to use obfuscation where a good binary code would be enough protection. 

The basic structure of the byte code is to make use of ASTs - Abstract Syntax Trees - to code up expressions. An AST is simply a tree consisting of operators and operands and once you have an AST it is very quick for a VM to evaluate it simply by walking the tree. It also means you can use a standard compiler front end like LLVM to spit out an AST from your favurite language - mostly C/C++ at the moment. The binary representation is up to 20 times faster to parse than asm.js and it creates smaller files. This should speed up load times as well as run times.

There is no full implementation of wasm at the moment the documents refer to a minimally viable prototype being the first aim. There is a polyfill that will allow wasm to run on an unmodified JavaScript Engine, but the key to the future is making wasm native on all JavaScript engines. A asm.js to wasm converter and an experimental version of Google's V8 engine are also available.

There is only an informal discussion group but it has all the important people on board and is being actively supported by JavaScript creator Brendan Eich. Things are only likely to go wrong when it moves to become a web standard.

Wasm is good news and as when it arrives we will be even closer to running at native code speeds in the browser, but it is worth noting that viewed as an assembler wasm is still a fairly high level construct.

The development from JavaScript to asm.js to wasm is sort of logical, but many programmers will be thinking that this is a very round about route to a byte code for the web. It would have been fairly easy to simply allow installable VMs, JavaScript engines included, and make the browser really the equivalent of the OS. Of course the problem is security and wasm has the advantage of not changing JavaScript's security model. 




ScyllaDB 6 Adds Node Distribution Feature

ScyllaDB 6.0 has been released with two major features that change the way it works: a dynamic way to distribute data across nodes that significantly improves scalability; and support for strongly con [ ... ]

Paul Allen's Living Computer Museum Going, Going, Gone

The Seattle-based Living Computer Museum, founded in 2012 by Paul Allen to preserve vintage and heritage computers for posterity has closed and its collection will be sold at auction by Christies in S [ ... ]

More News


kotlin book



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

Last Updated ( Thursday, 16 February 2023 )