wasmi
wasmi copied to clipboard
Optimization: pre-load default memory bytes upon `Instance` reset in executor
Currently when executing wasmi bytecode there is the so-called InstanceCache which caches data frequently used during wasmi bytecode execution such as the default Memory bytes.
Whenever calling a function that originates from a different Instance this InstanceCache and all of its cached data is reset.
These default Memory bytes are loaded upon their first use after such an InstanceCache reset. The upside is that default Memory query is not done if no instructions interacting with the default Memory are executed. The downside is that this incurs a minor dispatch for every such instruction.
The idea behind this issue is to pre-load the default Memory bytes upon resetting the InstanceCache and when there is no default Memory to simply use a static [] as placeholder default memory bytes.
The downside of this approach is that resetting the InstanceCache becomes slightly more expensive, however, instructions interacting with the default Memory become a bit cheaper.
A wasmi execution that calls a lot of functions imported from different Wasm module instances or one that successfully grows the default Memory often (which is unlikely) might regress in their performance, whereas a wasmi execution that has a lot of Memory instructions such as i32.load, f64.store, etc. should see a performance improvement.
Further benchmarks are going to be needed once this has been implemented.
- [ ] Implement pre-loading of the default
Memorybytes as described above. - [ ] Conduct benchmarks and explain the results.
- [ ] If needed: Maybe introduce new benchmarks that properly show the performance improvements.
This issue was tackled by this PR: https://github.com/paritytech/wasmi/pull/769
The outcome was not satisfying but maybe the implementation was problematic and could have been improved in order to yield successful results.
Closed due to bad experimental results: https://github.com/wasmi-labs/wasmi/issues/756#issuecomment-1826304163