Asm.js Gets Faster
Written by Ian Elliot   
Friday, 20 December 2013

Asm.js is a subset of standard JavaScript that is simple enough for JavaScript engines to optimize. Now Mozilla claims that with some new improvements it is only 1.5 times slower than native code. How and why?

Asm.js is a restricted subset of JavaScript that make use of standard JavaScript features to allow a JavaScript engine to infer the type of a variable and so perform many optimizations which are not possible with the full flexibility of the language. This subset is suitable for treatment as a low level language that can be the target of other language compilers. For example, Emscripten compiles C/C++ to Asm.js and it has been used to create many impressive ports of well known C/C++ applications so that they can run in the browser at close to native code performance. 



However, close isn't the same as running at native code speeds and anything that can be done to speed things up is welcome. Previously Mozilla demonstrated that Asm.js could run typical native code programs at about 2x slower at worst. Now, with a change to the way floating point arithmetic is handled, this have been improved to about 1.5x slower. 

The problem with JavaScript as an assembly language is that it doesn't support the range of datatypes that are needed for optimization. This is good for human programmers because they can simply use a numeric variable and not worry about the difference between int, int32, float, float32 or float64. JavaScript always uses float64 and this provides maximum precision, but not always maximum efficiency. 

The biggest single improvement that Mozilla has made to its SpiderMonkey engine is to add a float32 numeric type to asm.js. This allows the translation of float32 arithmetic in a C/C++ program directly into float32 arithmetic in asm.js. This is also backed up by an earlier float32 optimization introduced into Firefox that benefits JavaScript more generally. 

You can see the performance of asm.js in the following chart - firefox f32 is using 32-bit floating point. 


You can see that, while firefox f32 is still nearly aways slower than native code, it is approaching the typical speed range of native code. 

Of course, the alternative approach to making code run faster in the browser is being developed and promoted by Google in the form of its native client facilities, NaCL and Pepper. At the moment only Google Chrome supports NaCL, but Firefox, Chrome and Opera support asm.js to greater or lesser extents. It appears that asm.js is becoming a very important part of the technology stack. 

To quote Alon Zakai on the Mozilla blog:

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


More Information

Gap between asm.js and native performance gets even narrower with float32 optimizations

Related Articles

Java, ASM.js Or Native - Which Is Faster?       

Octane 2.0 Released       

JavaScript Assembly Language       

Firefox Runs JavaScript Games At Native Speed       

Firefox 22 Released and 23 in Beta    


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.






or email your comment to:



Cassandra 4.1 Focuses On Pluggability

Version 4.1 of Apache Cassandra, the open source NoSQL distributed database, has been released. The team says this release paves the way to a more cloud-native future for the project by externalizing  [ ... ]

.NET 8 Preview 1 Announced

The first preview of .NET 8 has been announced, with a focus on cloud-native and cross-platform development with MAUI and Blazor.

More News



Last Updated ( Friday, 20 December 2013 )