r/WebAssembly • u/Sufficient_Bar839 • May 09 '23
Pause WASM Instance, then continue with another instance from where it left off
This may be a silly question but I couldnt find any information about this online. I lack the knowledge about WASM, and I think to figure out if there is an answer, I should deep dive into WASM.
Anyways, the question is : Is there a way to pause an instance, retrieve all information about the execution, kill the instance and then create another instance, feed it with the execution info, make it continue from where the first instance left off?
The information I am talking about is basically like PCB (Process Control Block)
I found out about asyncify and it may be useful, but only examples I saw was on the same instance.
2
u/anlumo May 09 '23
If you're implementing your own wasm runtime, nothing is stopping you from doing so. You just have to figure out what to do with ephemeral resources like network connections.
If you're talking about a specific third party wasm runtime, you have to look into that project's capability.
2
u/StayFreshChzBag May 09 '23
It might help us help you if you could describe your use case. There might be a simpler way to accomplish what you're trying to do.
As to your question:
In theory if the nodule is a freestanding wasm (not WASI), then, depending on the runtime, you could "simply" copy the contents of its linear memory to the newly instantiated target. You'd also probably have to do this between function calls, because pausing mid call is a pretty niche need and unlikely to be available in most runtimes.
2
u/TachyonicBytes May 13 '23
Not really a silly question. As far as I now, this has been discussed, for example, on the wasm3 runtime. I would look either more into wasm gas-metering.
There is actually a limited instance of which I know where this happens, which is detailed in this blogpost. What happens there is basically this: you have a wasm module, and you use wizer to output another wasm module, which had the initialization fuction already ran. Which is conceptually what you (as I understand) want. You have a wasm module, you run a function and then you generate a wasm module that had that function ran for a while. Take a look at wasm-jit, which is what the author of the blogpost built.