3 ms·
"we built a small wrapper around the WebAssembly component in V8, that allows it to also consume native code input via asm.js in addition to the native bytecode
by acqq 10y ago
"we built a small wrapper around the WebAssembly component in V8, that allows it to also consume native code input via asm.js in addition to the native bytecode format."
It's written between the lines, but how I understand it, the optimizations they produce are finally the same that Mozilla did since it introduced asm.js. Later on it's shown in the example:
This:
"use asm";
function f(x) {
x = +x;
x = x * x;
return +x;
}
Is basically reduced to:
0x10a04e985b0d 13 c5f359c9 vmulsd xmm1,xmm1,xmm1
0x10a04e985b11 17 c3 retl
Of course, before they acknowledged asm.js, the working part of JIT-ed code was much, much bigger, the author describes it:
"It’s a lot heavier since it has to use the JavaScript calling convention."
- azakai 10y agoYes, the approach shares elements with what Mozilla and later Microsoft have been doing. It derives types from asm.js annotations, and uses that to perform AOT compilation.
- acqq 10y agoWhat I wanted to suggest is that they didn't have to wait for WebAssembly. Even if it's now presented as "a small wrapper around the WebAssembly" it was possible to do that since Mozilla introduced asm.js, as in the "ams.js" block is exactly enough information that enables for what they did now.
- fenomas 10y agoMaybe I'm dumb, but wouldn't a sufficiently clever optimizer compile the quoted function into the quoted output, even if the "use asm" tag was omitted? What is the significance of asm.js here?
- azakai 10y agoIn theory yes, a smart enough JIT could figure this out. That was in fact v8's strategy for a while. But in practice, it's just not as effective. In a small function like that things are fairly simple, but with large code it takes time and resources for the optimizer to figure out all the types. That leads to noticeable slowness and pauses for recompilation etc. Instead of that, asm.js gives you the option to just receive the types up front.
- acqq 10y agoAnswered in asm.js FAQ: "Q. Why not just keep optimizing JavaScript JIT compilers instead? A. No need to stop! But JIT compilers have less predictable performance based on complicated heuristics. The asm.js model provides a model closer to C/C++ by eliminating dynamic type guards, boxed values, and garbage collection. Q. Isn't it inefficient to have to run the code through a JavaScript interpreter before compiling? A. Because of the directive prologue, a JavaScript engine can immediately recognize asm.js code at compile-time and immediately compile it to assembly language, with no need to ever run the code through an interpreter."