

ASM.JS and JavaScript V8/Node.js? - Pharohbot

Could ASM.JS be implemented into the JavaScript V8 engine to make it much faster which in turn makes Node.js overall even faster than it is now? So basically all the JS you code with Node would be compiled to asm.js and&#x2F;or Asm.js be added to V8 to create a faster VM and faster platform? Is it possible and will it happen?
======
kjksf
Asm.js already runs on V8. It's just not fast. If you want to see if/when
asm.js becomes fast in V8, see
[https://code.google.com/p/v8/issues/detail?id=2599](https://code.google.com/p/v8/issues/detail?id=2599)

However, you don't seem to understand what asm.js is.

Asm.js is not JavaScript.

Syntactically it does look like JavaScript but it's really bytecode emulating
CPU in JavaScript clothing.

As such asm.js is used to execute C code bases cross-compiled to asm.js with a
tool like emscripten.

There is no such thing as "compiling JavaScript to asm.js" because there's no
point. V8 (and every other modern JS VM) already compiles JavaScript to
optimized CPU instruction set so it doesn't make sense to do JavaScript ->
asm.js -> CPU instructions set.

To re-iterate: asm.js targets the same use case as p(nacl) i.e. compiling
C/C++ code bases to something that can be executed in the web.

See [http://mrale.ph/blog/2013/03/28/why-asmjs-bothers-
me.html](http://mrale.ph/blog/2013/03/28/why-asmjs-bothers-me.html) for more
info.

~~~
marcosscriven
asm.js certainly is Javascript - that's a very important aspect of it.

From [http://asmjs.org/](http://asmjs.org/):

"an extraordinarily optimizable, low-level subset of JavaScript"

------
marcosscriven
I'm not an asm.js expert by anyway means, but I did have some success using
it. So here's some basic facts:

1) asm.js _is_ Javascript, albeit a strict subset

2) asm.js is not Emscripten. Emscripten is rather a tool that converts LLVM IR
to asm.js - in fact, before asm.js was released, Emscripten still worked,
albeit significantly slower.

3) While you can't 'compile' Javascript to asm.js, you could in theory
manually convert it - the reason it's so closely associated with C/C++ is that
there's type information available to do the conversion to asm.js
automatically

4) Just as an example, asm.js works by doing things like bitwise ORing numbers
with zero to make it possible for the Javascript engine to immediately know
you're actually only dealing with integers. In that sense it gives you AOT-
like potential, rather than running the loop a few hundred times to see what
you're getting before JITing it.

With V8, Google seem to be taking the approach it's better to optimise more
generally, rather than focussing on asm.js.

