Open
Description
Web assembly is already available ( behind flag ) in node 6, so might worth trying it as a next level of "Userspace JIT" approach
Some overview:
https://ia601503.us.archive.org/32/items/vmss16/titzer.pdf
Working wasm examples ( run with node --expose-wasm
):
function fib(stdlib, foreign, heap) {
"use asm";
var i32 = new stdlib.Int32Array(heap);
var f64 = new stdlib.Float64Array(heap);
var imul = stdlib.Math.imul;
function fib(n) {
n = n|0;
if (n >>> 0 < 3) {
return 1|0;
}
return (fib((n-1)|0) + fib((n-2)|0))|0;
}
return {
fib:fib
};
}
var m = _WASMEXP_.instantiateModuleFromAsm(fib.toString());
var asmFib = m.fib;
var n = 38;
console.time("ASM:fib(" + n + ")");
var f = asmFib(n, global);
console.log(f);
console.timeEnd("ASM:fib(" + n + ")");
binary wasm:
https://gist.github.com/sidorares/90607f73b499f2ccb7dd908a080ebe5d
Problems:
- no objects or strings in output. The only possible way I see now: generate json representation on the heap and use
JSON.parse
. Might still be fast! ( JSON.parse is very fast and often surpass manual object creation in speed ) - quite a lot of work for a unknown performance gain