Asm.js Gets Faster
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."



Computational Thinking For Kids

The Bebras Challenge 2015, intended to introduce school students as young as 8 to computational problem solving, takes place from November 9 to 22. Registration is open until November 8, so teachers s [ ... ]

Pivot Podcast Concludes - What Will Be Revealed?

The eighth episode of GE's Pivot Podcast has just been released. Will Sam and Ethan find the answers they need to launch DroneAble, which has grown in concept from an app to a start up company?

More News



Last Updated ( Friday, 20 December 2013 )

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