Feeds

Mozilla: Native code? No, it's JavaScript, only it's BLAZING FAST

New tech promises browser apps at near native speed

SANS - Survey on application security programs

The Mozilla Foundation says it has reached an important milestone in the quest to improve JavaScript performance, with some JavaScript benchmarks now running only around 1.5 times slower than when the equivalent algorithms are compiled and executed as native binary code.

"That's a big improvement from earlier this year, when as mentioned before things were closer to 2x slower than native," Mozilla researcher Alon Zakai said in a blog post on Friday.

There is a catch, however. Strictly speaking, the benchmarks Mozilla has tested were implemented not in hand-coded JavaScript, but in Asm.js.

Asm.js is JavaScript. It will run in any browser. But it's only a subset of the full JavaScript language. It intentionally ignores some of the more ambiguous features of JavaScript syntax, leaving a dialect that is more streamlined and – most importantly – easier for runtime engines to optimize for performance.

The idea is that while traditional JavaScript is a syntactically rich, high-level language like C or Python, JavaScript written to the Asm.js spec is closer to assembly language. In fact, much like assembly language, the structure and syntax of Asm.js code is so arcane that application developers are advised not to try to write it by hand. Instead, Asm.js is designed to be output by compilers.

One such compiler is Emscripten, which Zakai and others have developed at Mozilla. Emscripten allows C/C++ source code to be compiled into JavaScript, including Asm.js. It's the tool that makes possible such impressive demos as the in-browser 3D first-person shooter game that Mozilla unveiled last year.

But producing code in Asm.js is only half of the solution. To get the biggest performance gains, explicit support for Asm.js needs to be implemented in JavaScript execution engines.

SpiderMonkey, the JavaScript engine that comes with Mozilla's own Firefox browser, has shipped with Asm.js support enabled by default since Firefox 22 in June. On Friday, Zakai said that continuing improvements to the engine have been largely responsible for the latest Asm.js speed gains.

Specifically, the newest builds of Firefox and Emscripten both include support for instructions that allow SpiderMonkey to run some kinds of floating-point calculations using 32-bit values rather than the typical 64-bit double-precision ones.

Chart showing JavaScript performance gains with Asm.js optimizations

With new optimizations, JavaScript performance is closing in on that of native code (click to enlarge)

According to Zakai, with these optimizations enabled, Asm.js code running in SpiderMonkey can run nearly as fast, and on rare occasions even faster, than native code benchmarks produced by C compilers like clang and gcc.

"Overall, what this shows is that 'native speed' is not a single number, but a range," Zakai wrote. "It looks like asm.js on Firefox is very close to that range – that is, while it's on average slower than clang and gcc, the amount it is slower by is not far off from how much native compilers differ amongst themselves."

So are JavaScript applications everywhere due for a speedup? Not quite. Although support for the new 32-bit optimizations is available in Emscripten now, it's not enabled by default because it increases overall code size and it can actually hurt performance in some cases. Zakai says Mozilla is working on ways to limit these problems.

What the latest findings illustrate, however, is that it is still possible to squeeze more speed out of browser-based applications even as the performance of JavaScript VMs reaches its peak, without resorting to unpopular workarounds like Google's NaCl.

"And even the current performance numbers – 1.5x slower than native, or better – are not the limit of what can be achieved," Zakai writes, "as there are still big improvements either under way or in planning, both in emscripten and in JavaScript engines." ®

High performance access to file storage

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
IRS boss on XP migration: 'Classic fix the airplane while you're flying it attempt'
Plus: Condoleezza Rice at Dropbox 'maybe she can find ... weapons of mass destruction'
Ditch the sync, paddle in the Streem: Upstart offers syncless sharing
Upload, delete and carry on sharing afterwards?
New Facebook phone app allows you to stalk your mates
Nearby Friends feature goes live in a few weeks
Microsoft TIER SMEAR changes app prices whether devs ask or not
Some go up, some go down, Redmond goes silent
prev story

Whitepapers

Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.