Stream: general

Topic: reusing a memory across multiple sequential instances


view this post on Zulip Daniel Salvadori (Nov 03 2022 at 00:13):

The docs for Store state: "No form of GC is implemented at this time so once an instance is created within a Store it will not be deallocated until the Store itself is dropped."
I need to reuse a memory over several sequential Wasm instances. Currently it appears I'm forced to copy the memory in and out since it's not recommended to reuse a Store. Are there any workarounds or plans to support this? Anything I can do to help allow this use case?

view this post on Zulip Dan Gohman (Nov 03 2022 at 00:15):

Would the pooling allocation strategy work for this? https://docs.rs/wasmtime/latest/wasmtime/enum.InstanceAllocationStrategy.html#method.pooling

view this post on Zulip Daniel Salvadori (Nov 03 2022 at 00:53):

Probably! I'll give it a shot and let you know! Thanks!!

view this post on Zulip Daniel Salvadori (Nov 03 2022 at 14:36):

@Dan Gohman As far as I can tell the pooling allocation strategy doesn't resolve my problem because a store owns the memory, and to return resources to a pool I need to drop a store (and thus memory). So I would still need to copy data out of a memory, drop the store, create a new store+memory, and copy data in, which is incredibly inefficient.

The alternative is to reuse the same store across an unbounded number of sequential instances but Wasmtime explicitly states not to do that because of no garbage-collection "at this time". Does anyone know if GC will be implemented at some point? Meanwhile, what would be recommended - to reuse a Store with hopes that GC will be implemented in the future or copy data in/out?

view this post on Zulip Lann Martin (Nov 03 2022 at 14:48):

Another option might be to implement your own MemoryCreator and return to a pool on drop

view this post on Zulip Daniel Salvadori (Nov 03 2022 at 14:53):

Interesting, that could work! Will try it, thanks!!


Last updated: Nov 22 2024 at 16:03 UTC