Firefox Runs JavaScript Games At Native Speed
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. 


This Just In: Fake News Packs a Lot in Title, Uses Simpler, Repetitive Content in Text Body, More Similar to Satire than Real News

Fake news, well you know it when you see it because it's news with its facts all wrong. Now researchers have concluded that this isn't the case. In fact fake news is more like satire than news in styl [ ... ]

Facebook Open Sources Litho Android UI Framework

Facebook's F8 conference often seems more like a place to announce its future directions than anything directly relevant to developers, but Litho should be of interest to any Android programmer.  [ ... ]

More News


Last Updated ( Thursday, 28 March 2013 )

RSS feed of news items only
I Programmer News
Copyright © 2017 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.