A new stage in the JavaScript speed race. OdinMonkey module speeds up low-level code 10 times

    The OdinMonkey module is part of the IonMonkey engine responsible for optimizing and compiling low-level Asm.js - on March 21 it was included in the Firefox Nightly build. What is Asm.js? - This is a subset of the JavaScript language that allows programming "at the assembler level" - without dynamic typing and memory allocation. In a sense, Asm.js is similar to Google Native Client technology, only with backward compatibility - the code written according to the Asm.js specification is the correct JavaScript code and will run on any engine only slower than with OdinMonkey.

    Asm.js allows in some cases to come close to the performance of native code - a C program compiled in Asm.js usually works only half as fast as the original:



    Asm.js uses rarely used language constructs like " | 0 " to indicate types . They are chosen so as not to affect the semantics of the standard JavaScript expressions, this is why Asm.js code will work in any browser today, and tomorrow, if support for "JavaScript assembler" appears in it, it will just start executing 10 times faster. Here is an example code on Asm.js:

    function foo(x, y) {
       var x = x|0;   // x имеет тип int
        var y = +y;    // y имеет тип double
        return +(x * y);   // функция возвращает double
    }
    


    The Asm.js standard and the OdinMonkey module primarily owe their existence to Luke Wagner, the author of Emscripten, a popular compiler from LLVM in JavaScript, which was repeatedly mentioned on Habré . The code generated by this compiler became the basis of the Asm.js. specification. By the way, the answers to frequently asked questions about Asm.js were recently translated by the habraiser Mithgol .

    At the moment, OdinMonkey can only be enabled in Firefox Nightly on x86 / x64 platforms under desktop Windows and Linux, and soon there will be support for MacOS X and ARM. To enable, you must set the flag javascript.options.​experimental_asmjstoabout:config. Since Asm.js is primarily intended for automatic generation by compilers, writing code on it manually is not very convenient. In the future, the Mozilla team expects to add support for more ergonomic low-level syntax, for example based on Low-Level JavaScript .

    To take a closer look at Asm.js, you can start with this presentation and this article . And you can continue by studying the official specification .


    Also popular now: