|
|
|
|
|
by pygy_
2986 days ago
|
|
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).https://mrale.ph/blog/2018/02/03/maybe-you-dont-need-rust-to... |
|