When I'm using wasmtime in an async context and I want to call the same client function multiple times concurrently, should I instantiate a new store each time I call the function?
Context: I'm trying to make NPC scripts for a game(state-machine alike), which would wait with on a mpsc channel for further user actions, but since those scripts run on the server-side I'd have to call the same script multiple times.
Currently wasmtime doesn't support concurrent calls of wasm, and additionally most wasms wouldn't support that either. You can invoke wasms in parallel via separate instances but any one instance can only have one concurrent call at a time
Not that stores and instances are relatively cheap though
Alex Crichton said:
Not that stores and instances are relatively cheap though
Presumably you meant to type "Note that" :smile:
oops yes, sorry!
Jonas Zunker said:
When I'm using wasmtime in an async context and I want to call the same client function multiple times concurrently, should I instantiate a new store each time I call the function?
Context: I'm trying to make NPC scripts for a game(state-machine alike), which would wait with on a mpsc channel for further user actions, but since those scripts run on the server-side I'd have to call the same script multiple times.
Yeah in our use case we just create multiple instances. Once we read the Module first time we can just clone the Module object pretty fast when initializing every new request. This was one wasmegde though also not sure if this is the right way but it works for us
Slightly faster for wasmtime: https://docs.rs/wasmtime/latest/wasmtime/struct.InstancePre.html
This is really cool
Last updated: Dec 23 2024 at 13:07 UTC