Skip to content

feat(component): add Accessor async InstancePre instantiation#13706

Open
Aditya1404Sal wants to merge 1 commit into
bytecodealliance:mainfrom
Aditya1404Sal:add-accessor-instantiate-async
Open

feat(component): add Accessor async InstancePre instantiation#13706
Aditya1404Sal wants to merge 1 commit into
bytecodealliance:mainfrom
Aditya1404Sal:add-accessor-instantiate-async

Conversation

@Aditya1404Sal

Copy link
Copy Markdown
Contributor

Summary

Add Accessor::instantiate_async, an Accessor-side helper for instantiating an InstancePre into the current concurrent store.

This is intended for embedders that are already inside StoreContextMut::run_concurrent and need to instantiate prepared components while using the concurrent component runtime.

Problem

Inside run_concurrent, embedders are given an Accessor rather than a direct StoreContextMut.

That works for accessing store data with Accessor::with and for calling already-instantiated component functions with call_concurrent, but there is currently no public API for instantiating an InstancePre into that same concurrent store.

For hosts with dynamic component graphs, this makes lazy instantiation not-possible. In my use case I had to either:

  • pre-instantiate possible callees before entering run_concurrent
  • avoid lazy linking :(

This is limiting for hosts that want to instantiate linked components on demand during async component execution.

Change

Add:

Accessor::instantiate_async(&InstancePre<T>) -> Result<Instance>

The method uses the existing Accessor TLS mechanism to recover the current concurrent store and then delegates to InstancePre::instantiate_async.

This keeps lazy instantiation within the active concurrent event loop, without requiring a separately-held StoreContextMut.

I would really appreciate feedback on whether this is the right API shape for exposing this capability (ie. through Accessor)

Validation

Added a component-model async test that:

  • prepares a component with Linker::instantiate_pre
  • enters StoreContextMut::run_concurrent
  • instantiates the same InstancePre twice through Accessor::instantiate_async
  • verifies linker-provided imports are available
  • calls exports from both instances with call_concurrent

Ran:

cargo test --test all accessor_can_instantiate_pre
cargo check -p wasmtime --features component-model,component-model-async,async

Allow embedders inside run_concurrent to lazily instantiate prepared components into the current concurrent store.

Signed-off-by: Aditya Salunkhe <aditya.salunkh919@gmail.com>
@github-actions github-actions Bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jun 22, 2026
@Aditya1404Sal Aditya1404Sal marked this pull request as ready for review June 22, 2026 20:44
@Aditya1404Sal Aditya1404Sal requested a review from a team as a code owner June 22, 2026 20:44
@Aditya1404Sal Aditya1404Sal requested review from dicej and removed request for a team June 22, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant