Stream: git-wasmtime

Topic: wasmtime / PR #11457 Refactor `InstanceAllocator` trait i...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2025 at 14:48):

alexcrichton opened PR #11457 from alexcrichton:instance-allocator-refactor to bytecodealliance:main:

Prior to this commit Wasmtime had an InstanceAllocatorImpl trait with a number of required methods as well as an InstanceAllocator trait with a number of provided impls. The InstanceAllocator trait is implemented for everything implementing InstanceAllocatorImpl to force users to be unable to override the default methods. When adding async support internally to Wasmtime these are going to need to be #[async_trait]-annotated-traits which adds a cost to async functions as a future needs to be heap-allocated.

The goal of this commit is to make this future async-ification a bit more optimal. Notably the InstanceAllocator trait is removed and replaced with inherent methods on impl dyn InstanceAllocatorImpl. After that the previous InstanceAllocatorImpl trait was renamed to InstanceAllocator meaning that there's just one InstanceAllocator trait which has inherent methods which cannot be overridden. A consequence of this is that the inherent methods are also forced to do virtual dispatch unlike before where they would internally use monomorphization to have static dispatch. Given the complexity of instance allocation this is expected to be a negligible cost, however.

The main benefit is that allocate_module, allocate_tables, and allocate_memories all get to be native async functions without the cost of #[async_trait]. Only allocation of a single table/memory will require an allocation of a future which in profiling helps reduce the cost of instantiation slightly.

Note that #[async_trait] is not currently used, this commit is just preparation for its eventual use.

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2025 at 14:48):

alexcrichton requested fitzgen for a review on PR #11457.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2025 at 14:48):

alexcrichton requested wasmtime-core-reviewers for a review on PR #11457.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2025 at 16:43):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2025 at 17:04):

fitzgen merged PR #11457.


Last updated: Dec 06 2025 at 06:05 UTC