alexcrichton opened PR #11457 from alexcrichton:instance-allocator-refactor to bytecodealliance:main:
Prior to this commit Wasmtime had an
InstanceAllocatorImpltrait with a number of required methods as well as anInstanceAllocatortrait with a number of provided impls. TheInstanceAllocatortrait is implemented for everything implementingInstanceAllocatorImplto force users to be unable to override the default methods. When addingasyncsupport internally to Wasmtime these are going to need to be#[async_trait]-annotated-traits which adds a cost toasyncfunctions 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 theInstanceAllocatortrait is removed and replaced with inherent methods onimpl dyn InstanceAllocatorImpl. After that the previousInstanceAllocatorImpltrait was renamed toInstanceAllocatormeaning that there's just oneInstanceAllocatortrait 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, andallocate_memoriesall get to be nativeasyncfunctions 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:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested fitzgen for a review on PR #11457.
alexcrichton requested wasmtime-core-reviewers for a review on PR #11457.
fitzgen submitted PR review.
fitzgen merged PR #11457.
Last updated: Dec 06 2025 at 06:05 UTC