wasmi-labs / wasmi

WebAssembly (Wasm) interpreter.

Home Page:https://wasmi-labs.github.io/wasmi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle host function calls the same as other instructions in the Wasmi executor

Robbepop opened this issue · comments

Currently the Wasmi executor treats host function calls different to any other Wasmi bytecode instruction execution. The reason for that is simple: In order to invoke host functions the executor needs to know about the generic host state type T of the Store<T>.
One design principle of the current Wasmi executor is to make it non-generic and thus we introduced the non-generic StoreInner and made the Wasmi executor work on it instead of Store<T>. The obvious downside is that we need special treatment for host function calls which is ugly. Also it necessitates returning a large struct from the Wasmi executor which is not perfect for the optimizer to handle well and might be the performance issue we see on some platforms.

As an aside this refactoring will also greatly help if we are ever going to use tail call dispatch for the Wasmi executor once explicit tail calls become a thing in Rust.

I performed some local benchmarks with an experimental branch that simply removes host function calls and all their related handlers in the Wasmi executor to emulate what would happen if we were to implement this PR naively. The benchmarks showed no significant change indicating that either the experiment is flawed or that the optimizer can do a good enough job to reduce both cases to roughly the same assembly via aggressive inlining etc.

Further investigation needed.

The experimental branch can be found here: https://github.com/wasmi-labs/wasmi/tree/rf-experiment-host-fn-calls-nop