Why does asm.js deteriorate performance?

前端 未结 2 910
旧巷少年郎
旧巷少年郎 2021-01-31 02:41

Just to see how it performs, I wrote a very short asm.js module by hand, which simulates the 2D wave equation using 32-bit integer math and typed arrays (Int32Array). I have thr

2条回答
  •  时光说笑
    2021-01-31 03:11

    Actually asm.js has not been created to write code by hand but only as result of a compilation from other languages. As far as I know there are no tools that validate the asm.js code. Have you tried to write the code in C lang and use Emscripten to generate the asm.js code? I strongly suspect that the result would be quite different and optimized for asm.js.

    I think that mixing typed and untyped vars you only add complexity without any benefits. On the contrary the "asm.js" code is more complex: I tried to parse the asm.js and the plain functions on jointjs.com/demos/javascript-ast and the results are:

    • the plain js function has 137 nodes and 746 tokens
    • the asm.js function has 235 nodes and 1252 tokens

    I would say that if you have more instructions to execute in each loop it easily will be slower.

提交回复
热议问题