Stream: general

Topic: Should you create a store per concurrent call?


view this post on Zulip Jonas Zunker (Sep 24 2023 at 17:03):

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.

view this post on Zulip Alex Crichton (Sep 25 2023 at 16:19):

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

view this post on Zulip Alex Crichton (Sep 25 2023 at 16:20):

Not that stores and instances are relatively cheap though

view this post on Zulip Dan Gohman (Sep 25 2023 at 20:26):

Alex Crichton said:

Not that stores and instances are relatively cheap though

Presumably you meant to type "Note that" :smile:

view this post on Zulip Alex Crichton (Sep 25 2023 at 20:26):

oops yes, sorry!

view this post on Zulip Cwasi4wasm (Sep 26 2023 at 20:13):

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

view this post on Zulip Lann Martin (Sep 26 2023 at 22:28):

Slightly faster for wasmtime: https://docs.rs/wasmtime/latest/wasmtime/struct.InstancePre.html

view this post on Zulip Cwasi4wasm (Sep 28 2023 at 19:36):

This is really cool


Last updated: Oct 23 2024 at 20:03 UTC