Mozilla and Epic Games Port Unreal Engine 3 to the Web

Pulkit Chandna

Mozilla touts the gaming potential of its JavaScript-based answer to Google’s NaCL at GDC

Browser makers are notorious for taking disproportionately great pride in even the slightest of improvements in JavaScript performance. But when it comes to Mozilla Firefox’s ASM.js optimization module OdinMonkey most of the hype seems justified. On Wednesday, the non-profit outfit, which claims that its ASM.js implementation can deliver Javascript performance that’s only about twice as slow as native code, used its GDC session to showcase a web-based version of Epic’s Unreal Engine 3 that relies on ASM.js.

Before we go any further, a brief description of ASM.js is in order. The ASM.js spec describes it thus: “A strict subset of JavaScript that can be used as a low-level, efficient target language for compilers. This sublanguage effectively describes a safe virtual machine for memory-unsafe languages like C or C++. A combination of static and dynamic validation allows JavaScript engines to employ an ahead-of-time (AOT) optimizing compilation strategy for valid ASM.js code.”

Here’s what the official ASM.js FAQ page has to say regarding its performance: “It's early to say, but our preliminary benchmarks of C programs compiled to ASM.js are usually within a factor of 2 slowdown over native compilation with clang.”

The latest Firefox Nightly, which became available on March 21, includes an ASM.js optimization module for the browser’s JavaScript engine called OdinMonkey . If everything goes as per plan, the ASM.js module for SpiderMonkey will hit the stable channel in June.

The bottom line is that Mozilla is claiming that OdinMonkey can deliver ASM.js performance that is fast enough to be only about twice as slow as native code. To further put things into perspective, ASM.js code execution on Chrome and non-OdinMonkey Firefox is said to be about 10 and 12 times slower than native code, respectively.

This is enough, according to Mozilla, to “supercharge” gaming code in the browser. On Wednesday, Mozilla and Epic even gave a glimpse of the kind of rich 3D gaming experiences possible with this approach by showcasing a web-based version of the latter’s Unreal Engine 3 that uses the JavaScript optimization technology.

This ability of being able to deliver native-like performance (or, as a Chromium developer put it, “ the ability to run significant existing code bases with close to the speed of C inside the JavaScript engine ”) ties in pretty well with the non-profit organization’s Firefox OS initiative, which is all about Web apps. Mozilla has announced that game publishers like Disney, EA and ZeptoLab are working at using this technology to deliver top-rated games to mobile devices using the Web.

But why does Mozilla prefer this approach to the one being taken by Google with Native Client? This is what the official ASM.js site has to say: “The principal benefit of ASM.js over whole new technologies like NaCl and PNaCl is that it works today: existing JavaScript engines already optimize this style of code quite well. This means that developers can ship ASM.js today and it'll simply get faster over time. Another important benefit is that it's far simpler to implement, requiring very little additional machinery on top of existing JavaScript engines and no API compatibility layer.”

Around the web