Firefox Runs JavaScript Games At Native Speed
Written by Ian Elliot   
Thursday, 28 March 2013

Mozilla seems to be intent of making Firefox run JavaScript at close to native speeds. The latest news is that OdinMonkey is currently in Firefox Aurora and heading toward the final version of Firefox 22. To show just how good it is, the Unreal 3 game engine was demonstrated at GDC.

Most people would agreed that the browser is the new desktop. Programs that once would have run under Windows or Linux are now targeting the browser. What doesn't seem to be agreed is how to provide the performance that such apps need. Microsoft seems to think that all it has to do is optimize the JavaScript engine and that such apps probably should run under Windows. Google thinks that the solution is to allow native apps to run under the browser using NaCL.

Mozilla on the other hand has a very clever and subtle approach to the problem. Asm.js is a subset of standard JavaScript that allows static typing and which can be optimized much more than general JavaScript. OdinMonkey is a JavaScript engine that runs Asm.js code very fast - claimed to be at worse a factor of two - from native code. 

With OdinMonkey on board, Firefox can run any Asm.js code at speed. Any browser that doesn't have OdinMonkey or a similar optimized engine can simply run the code at the usual JavaScript speed. Hence this approach is 100% compatible and doesn't need modifications like NaCL.

You could write your programs in Asm.js, but the idea is that you will use other languages that compile to Asm.js. This opens up the possibility of converting existing desktop apps to run in the browser. Emscripten, for example, is a compiler that converts the LLVM bitcode intermediate language to either JavaScript or the asm.js subset. There are a number of compilers that target LLVM - llvm-gcc or clang, for example. So if you have an existing C/C++ program all you do is compile it to LLVM and then use Emscripten to convert it to Asm.js.

Of course things are not quite this simple as the code has to be modified to change the way that resources and frameworks are used, e.g. draw to canvas rather than a bitmap.  

 

odindiagram

 

To prove that it can be done, Mozilla and Epic games ported the Unreal 3 game engine in just 4 days. Given that Unreal 3 has over 1 million lines of code, we have to assume that most of it went across unmodified. The code runs at near native speed and is said to give a native feel to games running in the browser.

Mozilla is suggesting that this points the way for porting and implementing games from scratch, but there are some problems. In particular, there is the download time for the extensive resources that a 3D realistic game needs - textures, sounds, maps, models and so on. 

 

 

 

There are some interesting things to consider about where we find ourselves. Google is forging ahead with NaCL and an extended version PNaCL, which also uses the LLVM intermediate language to allow code to run in the browser at native speeds. The only difference between this and the Mozilla approach is that in Google's case the LLVM is JIT compiled to native code rather than asm.js.

Both Chrome and Firefox support enough modern HTML5 infrastructure to be compatible enough to expect that an LLVM program might run under both after suitable compilation. 

It might just be that LLVM is the language that will be the common target for high performance web apps. 

 

unreal3

 

This of course leaves IE out in the cold, but as it doesn't support OpenGL it has no 3D graphics and so is looking increasingly pointless as a platform for this sort of web app. There are rumors that IE11 might support OpenGL, but these have not been confirmed

Mozilla promises that you can examine the code of Unreal 3 and run the demo. Details are to be found on hacks.mozilla.org but there is nothing available at the current time. 

More Information

Asm.js

Emscripten

OdinMonkey

Benchmark Talk

Mandreel

Related Articles

JavaScript Assembly Language

Pit - F# to JavaScript Compiler

JavaScript to be the Default Language for Gnome

Ray Tracer in JavaScript

JavaScript JVM runs Java

Chrome Native Client Goes ARM and Portable

JavaScript Is Slow

Chrome native apps split the browser world

 

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

 

espbook

 

Comments




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

 

Banner


Looking Forward To NAO 7
03/11/2024

Introduced to the world in 2004 by its creator Bruno Maisonnier the kid-sized, autonomous humanoid robot NAO, turns 20 this year. At less than 2 ft tall, it is small in stature, but plays a big r [ ... ]



Visual Studio 17.12 Released Along With Aspire
25/11/2024

Visual Studio 2022 v17.12 is now available. The release can be used for .NET 9 projects and has a range of other improvements.


More News

 

Last Updated ( Sunday, 23 September 2018 )