Stream: wasmtime

Topic: Shared and per-plugin state patterns for WASM components


view this post on Zulip Sy Brand (Jun 13 2025 at 23:11):

Hey friends! I'm familiarising myself with the component model by building a simple plugin system. At the moment, I have a single Store that is shared between my plugins. This store tracks the main application state, which is primarily registrations of data coming from the plugins.

The basic pattern I have is: host calls plugin.call_init(), plugin calls host_please_register_stuff(some_stuff).

In the exported host_please_register_stuff function I need to identify from which plugin a given call came from, so that I can tie the registration to a plugin. As such, I have a comparatively large amount of global state, and a single integer plugin identifier that should be plugin-local state.

What's the most idiomatic way to do this with Wasmtime? The main ways I considered were:

Demonstration of a plugin system using WASM components - TartanLlama/guy-fighter

view this post on Zulip fitzgen (he/him) (Jun 13 2025 at 23:46):

I'm not sure I follow your application architecture exactly, but as a general rule of thumb: the less you can put in a single Store, and the shorter-lived they are, the better. An instance will not be dropped until its Store is dropped, for example, so if you keep a Store around for a long time and reuse it for many instances, you will hold memory alive longer than needed. Stores and Instances are built to be disposable, and can be instantiated quickly: https://docs.wasmtime.dev/examples-fast-instantiation.html

so given that, I think this is your best choice, of those presented:

Sy Brand said:

view this post on Zulip Sy Brand (Jun 14 2025 at 08:14):

Makes sense, thank you!


Last updated: Dec 06 2025 at 06:05 UTC