Wednesday 5 April 2017

Our guide to WebAssembly

Our guide to WebAssembly

WebAssembly is being touted as the future of the web but you’d be forgiven for wondering what on Earth it is. David Crookes explains all

What is WebAssembly?


WebAssembly (webassembly.org) is a relatively new web standard that has the potential to revolutionise how we use high-performance applications such as games, video players and imageediting software. Rather than making us download and install these resource-heavy apps, WebAssembly offers the potential to run them in your browser with full functionality. Developers say this will make computing far more convenient, with some going as far as calling it the dawn of a new web era.


But we already have web apps, don’t we?


Indeed we do. Over the years, we’ve become accustomed to running tools in our browsers; for example, we can word process using Google Docs, check our emails in Gmail and edit videos in YouTube, all without having to install any software. But these browser apps are typically not very sophisticated, whereas WebAssembly opens the door to more complex applications, all without the need for any plugins. It also allows them to run with near-native performance – that is, pretty much as if they are installed and running on your computer.

How much faster will WebAssembly apps be?


WebAssembly significantly improves start-up speeds, with the technology said to run 20 times faster than JavaScript. It is also claimed that apps using WebAssembly run just 1.13 times slower than your processor’s maximum speed.

How exactly does WebAssembly work?


We were afraid you’d ask that. To explain WebAssembly, we first need to get under its skin. At its heart, WebAssembly is a low-level programming language, which means it is effectively written in a code near-identical to the one that computers directly understand. When this is run, it allows developers to take the  source code of an app written in a higher-level computer language (one which uses more natural syntax) and turn it into code that a web browser can use (a process known as compiling).

All this takes place behind the scenes, so it won’t be obvious to you as you browse. Both the parsing (the analysis of the code) and the compilation take place before they reach your browser. This means the browser simply sees the low-level, machine-ready instructions and acts on them. Combined with the compact nature of WebAssembly, this makes the process very fast indeed.

So how do I use these apps?


All you need to do is visit a web page. You’ll be able to dive straight into playing a game, for example, and have it run fluidly, and you’ll also be able to move from device to device because the technology will be entirely portable. Additionally, there’s nothing to stop you launching a mobile app within your tablet’s browser, as long as it’s capable of using WebAssembly. Everything runs entirely within the web platform.

So we’ll all have to use apps?


It’s possible. There are certainly plenty of advantages to using WebAssembly. Because you don’t need to install software, the risk of malware infection should be reduced. Also, apps will become ‘cross-platform’, so it won’t matter which operating system you are using because they’ll simply run in any browser that supports WebAssembly. The standard of web-based apps should be improved, too. We’re likely to see more games, with virtual-reality and augmented-reality apps using the game engines Unity and Unreal Engine, and have high performance, browser-based computer-aided design and scientific visualisation software.

Will there also be a web app store?


No. One of the beauties of being able to simply visit a website to access an app is that it gets around the ‘walled gardens’ of app stores, especially on tablets and phones. Anyone will be able to publish apps to the web, which will ensure that software is accessible and in the full control of developers.

Who is behind WebAssembly?


Development is being driven by the W3C WebAssembly Community Group (bit.ly/wa420), which was launched in April 2015 with the backing of the Mozilla Foundation, Microsoft, Google and Apple. There is a concerted and unusually cooperative effort to make WebAssembly a true standard, which is good news because it means that it will eventually find its way to all the major browsers.

Will developers have to learn a whole new language?


Not necessarily, and this is the exciting thing. Although Mozilla says it could change what it means to be a web developer, the idea of WebAssembly is that coders are able to create software in multiple languages. Among those languages is C++ and, given that C++ is so widely understood by coders (it is even used to create software as important as Windows), many developers should feel right at home. Indeed, developers have been quick to see the potential and there is hope that WebAssembly will soon be used with Java, Swift and C# – languages that are often used for mobile apps.

Isn’t JavaScript still the top webprogramming language?


Well, yes, but WebAssembly will allow developers to bring their own applications to the web and go well beyond the capabilities served up by JavaScript, which is indeed a high-level programming language used to write much of the software we already see running in our browsers. The issue with JavaScript is that it was designed to be easy for novice developers, but it isn’t ideal for starting large applications quickly, whereas WebAssembly is. JavaScript has also been abused by hackers as a way to run malicious scripts.

Will WebAssembly replace JavaScript?


It’s very unlikely at this stage, given how widely used JavaScript remains. Although it’s true that Mozilla, Microsoft and Google have made separate attempts to extend JavaScript by releasing Asm.js, Typescript and NACL, respectively, WebAssembly is intended to broaden the number of languages that can be compiled to the web rather than replace JavaScript altogether. Indeed, WebAssembly will allow its applications to integrate with JavaScript so there will be room for both languages for some time yet. What will happen as WebAssembly gathers momentum remains to be seen, though.

So which web browsers are using WebAssembly today?


Version 57 of Chrome and version 52 of Firefox, which are the most recent stable releases, are both WebAssembly-enabled. Microsoft Edge and Safari will follow soon. There’s not a huge amount of support around at the moment but the creators of the game engine Unity, for instance, have been working on switching its WebGL platform to WebAssembly byte code in supported browsers. WebGL allows interactive 3D and 2D graphics to be rendered, and WebAssembly will make this faster and less resource-hungry.