I'm trying to figure out both if it's possible to suspend an arbitrary runtime of WASM and understand how that can be done. As best as I understand one could use Epochs but from the documentation it sounds like that causes an interrupt (please correct me if I'm wrong, as I don't understand epochs). Outside of that theoretically I could define some atomic interface but that would result in the WASM runtime having a busy loop if implemented poorly so that likely wouldn't work if I'm trying to run foreign user code without issue.
I suppose the core of my question is, is there any way to pause or suspend a runtime for performance reasons and resume it at a later point? If there are any examples for this that would also be greatly appreciated
Wasmtime supports this with the async mode of executing wasm. Suspension of wasm is modeled as a yield of Poll::NotReady
from the future representing wasm computation. You can integrate this into a larger async system but you can also just save off the future on the side for later execution if you'd like to.
Suspension points are introduced with either fuel or epochs. Fuel will yield after some amount of fuel has been consumed and epochs yield once the configure epoch has been met. Both have various advantages and disadvantages, but for the fastest runtime speed you'll want to use epochs.
Last updated: Nov 22 2024 at 16:03 UTC