
About twelve hours ago, John Rezig
clicked Twitter to Twitter that at the
Google I / O conference it was announced that
Asm.js support in the V8 engine and in the Google Chrome browser was improved.
Since Asm.js was mentioned
at Habrahabr ( 1 ,
2 ), its merits could become known to many readers. The more pleasant it is for them to anticipate in the very near future the appearance of these advantages not only in the Firefox browser (where they were first introduced by the Mozilla Foundation), but also in the V8 engine (and therefore in
the Node.js engine built on its basis
!) in the Google Chrome browser.
But for those readers who have so far missed this novelty by themselves, I also briefly recall the essence.
Asm.js is a special subset of the JavaScript language: having limited itself to it in its script, the author of the script provides the opportunity to optimize the interpreted code not only at the time of execution
(just-in-time, JIT), but even in advance
(ahead-of-time, AOT) ), that is, it becomes possible for such a javascript to unambiguously pre-assign some machine code once. This effect is achieved at the cost of noticeable efforts at self-restraint. (In particular, using the
" | 0 "
operation and other similar special techniques, the type of value of each input parameter of the function, as well as the output value, is uniquely specified and unchanged.) But its result is an unprecedented increase in the speed of javascript execution - now in speed inferior to the compiled program (in C
or C ++) no more than twice.
')
The main direction of practical application of Asm.js is not even in the field of manual programming (in which conscious adherence to Asm.js restrictions can be unacceptable for a programmer), but in the field of fully automatic transcompilation (translation into JavaScript from other programming languages) is enough complex programs and libraries that become no less cross-platform than JavaScript itself.
Emscripten is the most well-known tool for such a
trans-compilation , and in part also
Mandreel .
We are on the verge of such a future in which many programs from among those working with the command line (not requiring a GUI) can immediately be made cross-platform
(Node.js will ensure their execution on Windows, Mac OS X and Linux), for which will compile them into javascript (using LLVM and then Emscripten) instead of machine code - and double the speed of execution.
However,
impressive examples on the Emscripten page vividly show that some such graphical applications can be transferred, which are able to work
via EGL instead of a specific graphics API (OpenGL, or OpenGL ES, or OpenVG). However, such applications Node.js will not be enough - they will need to be transferred to the Web, that is, the execution of applications in browsers. Firefox and the Google Chrome browser that joined in support of Asm.js will execute them with the aforementioned unprecedented speed. But it is not difficult to foresee that all other browsers (IE, Opera, Safari, and so on) will also be able to execute them indiscriminately (because
Asm.js is a subset of ordinary JavaScript); the only difference will be in the speed of execution.