I have been reading about asm.js and web assembly recently:
我一直在读关于asm的文章。js和web assembly最近:
http://ejohn.org/blog/asmjs-javascript-compile-target/
http://ejohn.org/blog/asmjs-javascript-compile-target/
https://brendaneich.com/2015/06/from-asm-js-to-webassembly/
https://brendaneich.com/2015/06/from-asm-js-to-webassembly/
I am still confused about a few things:
我仍然对一些事情感到困惑:
- Is asm.js code compiled in time and run? Compiled into what?
- asm。在时间和运行中编译的js代码?编译成什么?
- Other than asm.js being text and wasm (web assembly) being binary, what are the differences between the 2?
- asm。js是文本,wasm (web assembly)是二进制,这两者有什么区别?
- 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代码编译为wasm吗?或
- python interpreter (Cpython) compiled into wasm and interpret python?
- python解释器(Cpython)编译成wasm并解释python吗?
- 对于在浏览器中运行的其他脚本语言,这意味着什么?以python为例,将python代码编译为wasm吗?还是将python解释器(Cpython)编译成wasm并解释python?
3 个解决方案
#1
27
Is asm.js code compiled in time and run? Compiled into what?
asm。在时间和运行中编译的js代码?编译成什么?
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.
asm。js是常规的javascript代码,并由js解释器编译成字节码。但是,使用asm支持的解释器应该进行提前编译,并且可能会因为静态类型而生成更有效的代码表示。有关详细信息,请参阅http://asmjs.org/。
what are the differences between asm and wasm (other than text vs binary)?
asm和wasm之间有什么区别(除了文本和二进制)?
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.
没有,现在。wasm应该是向后兼容的,可以编译成asm(同样可以作为普通的JS执行)。但是,随着对它的支持的增加,它将来可能会扩展更多的特性。
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.
而后者,因为Python仍然需要解释。不需要解释器的脚本语言当然可以直接编译到asm中,因为有一个编译器(chain)支持它作为目标。
#2
36
asm.js is a subset of JS with "highly optimizable" instructions. Basically you can declare the type (int, float) and the js engine (in the browsers but also the node.js one) will execute the instructions faster. It has benefits if your app does a lot of calculation or graphic if used together with WebGL.
asm。js是具有“高度优化”指令的js的子集。基本上,您可以声明类型(int, float)和js引擎(在浏览器中,也可以声明节点)。将更快地执行指令。如果您的应用程序与WebGL一起使用,进行大量的计算或图形处理,那么它将带来很多好处。
web assembly is a binary format for JS, all JS, not only asm.js. It's not a bytecode, it's a binary encoding of the AST that the parser calculates. It has 2 big benefits:
web程序集是JS的二进制格式,所有的JS,不仅仅是JS。它不是字节码,而是解析器计算的AST的二进制编码。它有两个好处:
- the JS engine can skip the parsing step
- JS引擎可以跳过解析步骤
- it's much more compact than the JS original source
- 它比JS原始源代码更紧凑
We already can write code for browsers that isn't JS: EMSCripten can compile c++ code in JS code. Other transcompiler are already available to compile your code into JS. Using asm.js that code can run faster when it does math. Using web assembly that code will be more compact and the browser will be able to process it faster (because it will be able to skip the parsing). You won't have a new plugin to load like DirectX, JavaApplets, Flash or Silverlight because everything will run in the JS sandbox.
我们已经可以为非JS的浏览器编写代码:EMSCripten可以用JS代码编译c++代码。其他的转编译器已经可用来编译您的代码到JS中。使用asm。这段代码在进行数学运算时可以运行得更快。使用web汇编,代码将更加紧凑,浏览器将能够更快地处理它(因为它将能够跳过解析)。你不会有一个新的插件来加载像DirectX, JavaApplets, Flash或Silverlight,因为所有的东西都将在JS沙箱中运行。
#3
17
Is asm.js code compiled in time and run? Compiled into what?
asm。在时间和运行中编译的js代码?编译成什么?
Different browsers compile asm.js code in different ways. As of August 2015:
不同的浏览器编译asm。js以不同的方式编码。截至2015年8月:
- Firefox compiles asm.js to machine code (and caches the machine code for future loads of the same asm.js) [1].
- Firefox编译asm。将js缓存到机器代码(并缓存机器代码,以便将来加载相同的asn .js)[1]。
- In Windows 10 as an experimental flag, Edge will also do some Ahead-of-Time validation and compilation of asm.js [2].
- 在Windows 10作为实验标志,Edge还会对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.
- Chrome特别认可asm一开始的“使用asm”指令。js更急切地解析和分析代码并调整编译启发式。
- Safari does no special processing of asm.js.
- Safari没有对asn .js进行特殊处理。
Other than asm.js being text and wasm (web assembly) being binary, what are the differences between the 2?
asm。js是文本,wasm (web assembly)是二进制,这两者有什么区别?
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.
asm。js只是JavaScript,因此必须严格按照JavaScript规范行事。作为一个新标准,WebAssembly能够修复一些JavaScript行为不是理想(从性能或编译角度)的情况[3]。在未来的[4]中,WebAssembly将能够添加在JavaScript中难以表达的特性。
What does this mean for other scripting languages, running in the browser? Take python for example, is it going to be
对于在浏览器中运行的其他脚本语言,这意味着什么?以python为例,它会是吗
- python code compiled to wasm? or
- python代码编译为wasm吗?或
- python interpreter (Cpython) compiled into wasm and interpret python?
- python解释器(Cpython)编译成wasm并解释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.
在v。1、在浏览器中运行Python的最简单的方法是将Python解释器编译为wasm,正如您所说。这意味着,例如,Python GC在wasm代码中运行,并手动管理wasm线性内存。已经有一个添加asm的实验项目。js后端到PyPy[5](这也适用于wasm)。它目前面临着asm的限制。可以通过wasm的动态链接未来特性来解决这个问题。进一步说,wasm寻求同时提供GC集成和JIT编译支持,这两种支持都可以使与Web平台的集成更有效、更自然。
#1
27
Is asm.js code compiled in time and run? Compiled into what?
asm。在时间和运行中编译的js代码?编译成什么?
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.
asm。js是常规的javascript代码,并由js解释器编译成字节码。但是,使用asm支持的解释器应该进行提前编译,并且可能会因为静态类型而生成更有效的代码表示。有关详细信息,请参阅http://asmjs.org/。
what are the differences between asm and wasm (other than text vs binary)?
asm和wasm之间有什么区别(除了文本和二进制)?
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.
没有,现在。wasm应该是向后兼容的,可以编译成asm(同样可以作为普通的JS执行)。但是,随着对它的支持的增加,它将来可能会扩展更多的特性。
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.
而后者,因为Python仍然需要解释。不需要解释器的脚本语言当然可以直接编译到asm中,因为有一个编译器(chain)支持它作为目标。
#2
36
asm.js is a subset of JS with "highly optimizable" instructions. Basically you can declare the type (int, float) and the js engine (in the browsers but also the node.js one) will execute the instructions faster. It has benefits if your app does a lot of calculation or graphic if used together with WebGL.
asm。js是具有“高度优化”指令的js的子集。基本上,您可以声明类型(int, float)和js引擎(在浏览器中,也可以声明节点)。将更快地执行指令。如果您的应用程序与WebGL一起使用,进行大量的计算或图形处理,那么它将带来很多好处。
web assembly is a binary format for JS, all JS, not only asm.js. It's not a bytecode, it's a binary encoding of the AST that the parser calculates. It has 2 big benefits:
web程序集是JS的二进制格式,所有的JS,不仅仅是JS。它不是字节码,而是解析器计算的AST的二进制编码。它有两个好处:
- the JS engine can skip the parsing step
- JS引擎可以跳过解析步骤
- it's much more compact than the JS original source
- 它比JS原始源代码更紧凑
We already can write code for browsers that isn't JS: EMSCripten can compile c++ code in JS code. Other transcompiler are already available to compile your code into JS. Using asm.js that code can run faster when it does math. Using web assembly that code will be more compact and the browser will be able to process it faster (because it will be able to skip the parsing). You won't have a new plugin to load like DirectX, JavaApplets, Flash or Silverlight because everything will run in the JS sandbox.
我们已经可以为非JS的浏览器编写代码:EMSCripten可以用JS代码编译c++代码。其他的转编译器已经可用来编译您的代码到JS中。使用asm。这段代码在进行数学运算时可以运行得更快。使用web汇编,代码将更加紧凑,浏览器将能够更快地处理它(因为它将能够跳过解析)。你不会有一个新的插件来加载像DirectX, JavaApplets, Flash或Silverlight,因为所有的东西都将在JS沙箱中运行。
#3
17
Is asm.js code compiled in time and run? Compiled into what?
asm。在时间和运行中编译的js代码?编译成什么?
Different browsers compile asm.js code in different ways. As of August 2015:
不同的浏览器编译asm。js以不同的方式编码。截至2015年8月:
- Firefox compiles asm.js to machine code (and caches the machine code for future loads of the same asm.js) [1].
- Firefox编译asm。将js缓存到机器代码(并缓存机器代码,以便将来加载相同的asn .js)[1]。
- In Windows 10 as an experimental flag, Edge will also do some Ahead-of-Time validation and compilation of asm.js [2].
- 在Windows 10作为实验标志,Edge还会对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.
- Chrome特别认可asm一开始的“使用asm”指令。js更急切地解析和分析代码并调整编译启发式。
- Safari does no special processing of asm.js.
- Safari没有对asn .js进行特殊处理。
Other than asm.js being text and wasm (web assembly) being binary, what are the differences between the 2?
asm。js是文本,wasm (web assembly)是二进制,这两者有什么区别?
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.
asm。js只是JavaScript,因此必须严格按照JavaScript规范行事。作为一个新标准,WebAssembly能够修复一些JavaScript行为不是理想(从性能或编译角度)的情况[3]。在未来的[4]中,WebAssembly将能够添加在JavaScript中难以表达的特性。
What does this mean for other scripting languages, running in the browser? Take python for example, is it going to be
对于在浏览器中运行的其他脚本语言,这意味着什么?以python为例,它会是吗
- python code compiled to wasm? or
- python代码编译为wasm吗?或
- python interpreter (Cpython) compiled into wasm and interpret python?
- python解释器(Cpython)编译成wasm并解释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.
在v。1、在浏览器中运行Python的最简单的方法是将Python解释器编译为wasm,正如您所说。这意味着,例如,Python GC在wasm代码中运行,并手动管理wasm线性内存。已经有一个添加asm的实验项目。js后端到PyPy[5](这也适用于wasm)。它目前面临着asm的限制。可以通过wasm的动态链接未来特性来解决这个问题。进一步说,wasm寻求同时提供GC集成和JIT编译支持,这两种支持都可以使与Web平台的集成更有效、更自然。