Re:Hello wasm-pack
by pygy_ on Thursday April 19, 2018 @08:15AM
(#16875183)
You can defeat inlining by using closures:
function thunk(x){ return function() { x() } }
const thunkFoo = thunk(foo)
const thunkBar = thunk(bar)
for(var i = 0; i < 10000; i++) {
thunkFoo()
thunkBar()
}
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 < 10000; i++) {
call(foo)
call(bar)
}
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).
Maybe you cal get away with
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...