javascriptasm.jswebassembly

What is the difference between asm.js and WebAssembly?


I have been reading about asm.js and WebAssembly recently:

http://ejohn.org/blog/asmjs-javascript-compile-target/

https://brendaneich.com/2015/06/from-asm-js-to-webassembly/

I am still confused about a few things:

  1. Is asm.js code compiled in time and run? Compiled into what?
  2. Other than asm.js being text and wasm (web assembly) being binary, what are the differences between the 2?
  3. What does this mean for other scripting languages, running in the browser? Take python for example, is it going to be
    • python code compiled to wasm? or
    • python interpreter (Cpython) compiled into wasm and interpret python?

Solution

  • Is asm.js code compiled in time and run? Compiled into what?

    asm.js is regular javascript code, and is compiled into bytecode by the JS interpreter as always. However, an interpreter with asm support is supposed to do ahead-of-time compilation, and possibly to generate more efficient code representation because of the static typing. See http://asmjs.org/ for details.

    what are the differences between asm and wasm (other than text vs binary)?

    None, for now. wasm is supposed to be backwards-compatible, compilable to asm (which again is executable as normal JS). It might however be extended with more features in the future as support for it grows.

    What does this mean for other scripting languages, running in the browser?

    The latter, rather, as Python still needs to be interpreted. Scripting languages that don't need an interpreter can of course be directly compiled to (w)asm, given that there is a compiler (chain) that supports it as a target.