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.  




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. 




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 but there is nothing available at the current time. 

More Information




Benchmark Talk


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.


raspberry pi books



or email your comment to:



One State's Quest For Digital Sovereignty

The news is that the German State is moving 30,000 PCs to LibreOffice. Why is this of significance?

Is Rust Safe?

Rust is our great hope for the future. Even if you are not using it you probably have heard of it and believe it is a safer language than C or C++. But is it really?

More News


Last Updated ( Sunday, 23 September 2018 )