Does anyone have a good sense of the current performance impact of crossing the boundary between JS and WASM? I've often thought it'd be great to be able to expose high-performance data structures (and other infrastructure-level stuff) via WASM and then make use of them from JavaScript, but I seem to recall that the interop performance cost is currently too high to make it worth doing, which leaves WASM mainly only u…
The cost is more than a JS->JS call, but not drastically so. Every argument must be converted from a number to an int32/float32/float64, which for SMI values is a single branch, for heap numbers a branch and a load. For other JS values, a ValueOf() operation on the JS value. V8 generates little wrappers for these, with inline conversions. It does not currently inline the little wrapper functions, nor use ICs for the…
function thunk(x){ return function() { x() } }
const thunkFoo = thunk(foo)
const thunkBar = thunk(bar)
for(var i = 0; i
This is why the "Maybe you don't need Rust to speed up your JS" author was creating functions dynamically using `new Function()`.Maybe you cal get away with
function call(x){ x() }
for(var i = 0; i
I didn't test the latter though, whereas the former is empirically slower if you call more than one thunk in your benckmark loop (a single thunk will have the call inlined).https://mrale.ph/blog/2018/02/03/maybe-you-dont-need-rust-to...