asm.js vs "a Javascript messze van a gepi kodtol"

IonMonkey

https://en.wikipedia.org/wiki/SpiderMonkey_%28software%29#Internals

IonMonkey is the name of Mozilla’s current JavaScript JIT compiler, which aims to enable many new optimizations that were impossible with the prior JägerMonkey architecture.

IonMonkey is a more traditional compiler: it translates SpiderMonkey bytecode into a control flow graph, using static single assignment form (SSA) for the intermediate representation. This architecture enables well-known optimizations from other programming languages to be used for JavaScript, including type specialization, function inlining, linear-scan register allocation, dead code elimination, and loop-invariant code motion.

The compiler can emit fast native code translations of JavaScript functions on the ARM, x86, and x86-64 platforms. It is the default engine since Firefox 18.

OdinMonkey

https://bugzilla.mozilla.org/show_bug.cgi?id=840282

(OdinMonkey is the project name for SpiderMonkey's optimizing compiler for asm.js (http://asmjs.org), built on top of the IonMonkey backend.)

At a high level, the interaction with the VM is as follows (see AsmJS.h):

1. After parsing (before emitting) a function, the frontend calls CompileAsmJS. CompileAsmJS performs type checking (a simple traversal of the parse tree) and simultaneously emits fully type-specialized IonMonkey MIR nodes.

2. If type checking succeeds, the entire asm.js module (collection of functions) is compiled by the IonMonkey backend and attached to the script. (Later, we'll do this in parallel and block in step 5.)

3. The frontend emits the script as bytecode with the first op being JSOP_LINKASMJS which, when executed, performs the dynamic validation of arguments as defined in the asm.js spec.

4. If the dynamic validation succeeds, the asm.js module's exports are returned as native functions that trampoline into the compiled code.

Things that slow down JavaScript

http://www.2ality.com/2013/02/asm-js.html

Current JavaScript is already quite fast, but a few mechanisms in engines limit its speed:
- Boxing (...),
- Just-in-time (JIT) compilation and runtime type checks (...),
- Automated garbage collection (...),
- Flexible memory layout (...)

asm.js code can produce executables that exhibit none of these drawbacks. They can be compiled “ahead of time” (before execution) and are faster than JIT-compiled ones.

Hozzászólások

És akkor lássuk a temérdek ASM.js-t használó terméket! :-)

Az ASM.js-sel máris majdnem ott vagyunk a programozás technológiájában, ahol voltunk a C programozási nyelv megjelenése előtt :-). Böngészőre fel!

Gyanítom, úgy gondolják, hogy gépi kód helyett az asm.js lesz a fordítás célnyelve…?
Egyébként számomra az nem világos, hogy hol van értelme ennek…? Egyelőre nem jut eszembe olyan terület, ami számításigényes és a) nincs már megoldva (grafika hardveres gyorsítása) vagy b) nem lassítaná le a kódot valamilyen API hívogatása (amiről merem feltételezni, hogy nincs optimalizálva)? (valaki okos ember, kérem cáfoljon meg a) vagy b) pontban…?)

int getRandomNumber() { return 4; }  // ← aláírás
//szabályos kockadobással választva. garantáltan véletlenszerű.  xkcd

Nem a teljesítményről van szó. Gépi kód definíció szerint olyan kód, amit a processzor natívan megeszik. Amíg nincs javascriptet futtató processzor, addig az asm.js nem gépi kód.

Lajk

Es +1

Ekkora buzzword projektnevet meg eletemben nem hallottam, mint az asmjs, jol valasztottak. Foleg annak tukreben, hogy tobbszor mondtak elotte: "a JavaScript a jovo assembly-je" (ez az allitas total unrelated az asmjs-hez, nagyjabol azert van igy, mert a JavaScript onmagaban nem eleg jo es nem eleg karbantarthato, ezert mast kell leforditani JavaScriptre, csak hat sebessegben kozel sincs a vegeredmeny ott, mint az "igazi assembly")

Akkor a Java bájtkódot is kinevezhetnéd gépi kódnak... Az is lefordul natívra futtatási időben.

asm.j es wasm meg csak NEM IS bajtkod (eminek lennie kellene)

"WebAssembly or wasm is an experimental efficient low-level programming language for in-browser client-side scripting" - Wikipedia

olyasmi, mint a C-- akart lenni anno

MIERT NEM LEHET EGY SZABVANYOS VM-ET CSINALNI?!

mindenki fejleszthetne abban amiben akar utana

--
NetBSD - Simplicity is prerequisite for reliability

Az a vicc, hogy nem is kellene VM-et csinálni, mert már van egy pár. Csak hozzá kellene drótozni a .NET-hez vagy a Java-hoz a HTML node-okat és az lehetne az új JavaScript. De talán az LLVM-nek is van biztonságos módja, azzal is meg lehetne csinálni.
De inkább nem adok ötleteket, mert még valaki megcsinálja, a JS fejlesztők éhenhalnak és az én lelkemen fog száradni.