What is the difference between asm.js and WebAssembly?

前端 未结 3 1348
天命终不由人
天命终不由人 2021-01-30 02:12

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-

3条回答
  •  悲&欢浪女
    2021-01-30 02:30

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

    Different browsers compile asm.js code in different ways. As of August 2015:

    • Firefox compiles asm.js to machine code (and caches the machine code for future loads of the same asm.js) [1].
    • In Windows 10 as an experimental flag, Edge will also do some Ahead-of-Time validation and compilation of asm.js [2].
    • Chrome specially recognizes the "use asm" directive at the beginning of asm.js to parse and analyze it the code more eagerly and tweak compilation heuristics.
    • Safari does no special processing of asm.js.

    Other than asm.js being text and wasm (web assembly) being binary, what are the differences between the 2?

    asm.js is just JavaScript and thus must behave exactly according to the JavaScript spec. As a new standard, WebAssembly is able to fix some corner cases where JavaScript behavior is not the ideal (from a performance or compilation perspective) [3]. In the future [4], WebAssembly will be able to add features that would otherwise be difficult to express in JavaScript.

    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?

    In v.1, the simplest way to run Python in a browser will be to compile a Python interpreter to wasm, as you said. This means, e.g., the Python GC is running in wasm code and manually managing the wasm linear memory. There has already been an experimental projects to add an asm.js backend to PyPy [5] (which could work just as well for wasm). It currently runs into limitations of asm.js that could be addressed by the dynamic linking future feature of wasm. Going further, wasm seeks to provide both GC integration and JIT compilation support both of which would allow more efficient and natural integration with the Web platform.

提交回复
热议问题