peterhuene commented on Issue #5:
@alexcrichton how awful would it be for
Configto expose a method taking anArc<dyn wasmtime_runtime::InstanceAllocator>? A complete non-starter?This asymmetry between the
InstanceAllocatortraits inwasmtimeandwasmtime-runtimenecessitate a back pointer fromwasmtime_runtime::Instanceto the allocator that created it so that the instance can call into the allocator upon deallocation of theInstanceHandle. I would really like to see the back pointer removed.Having
Configdirectly take the runtime trait would both simplify the code (i.e. no duplicated types in thewasmtimecrate) and eliminate the problem becauseStorecould use the runtime trait directly to deallocate the instance.This also means that if we open up the construction of
InstanceandInstanceHandlein the runtime so that instance allocators can be implemented in external crates, the Wasmtime API can use those implementations without introducing a wrapping type in thewasmtimecrate.
alexcrichton commented on Issue #5:
Heh I always start with the idea that anything is possible!
More to the point though a move like that would basically just be about the costs. It would cost us in terms of stability that we would have to document that usage of the method is not covered under our semver stability promises. That's probably feasible to do since we don't expect every user to have to implement this? Especially if we can bundle "common" allocation strategies in the
wasmtimecrate which are covered under the semver rules.Other than that the only other alternative I can think of is to sync up on the code you've got and see if anyone else is struck with inspiration of how to not have the dependency
fitzgen commented on Issue #5:
It wouldn't solve the duplication issue, but would solve the API stability issues: we could create a
wasmtime-traitscrate that defines just theInstanceAllocatortrait and necessary types (e.g.InstanceRequest) and say it has the same stability that thewasmtimecrate does (even re-export it fromwasmtime).
peterhuene commented on Issue #5:
What if we kept the sole
InstanceAllocatortrait inwasmtime_runtimewhere it would inherently be unstable (and thus implementors would know that their implementations are subject to breaks inwasmtime_runtime) but we would then considerConfig::with_instance_allocatorto itself be stable despite takingArc<dyn wasmtime_runtime::InstanceAllocator>as an argument? Thewasmtimecrate and any implementors ofInstanceAllocatormust agree on the definition anyway, right?The "out of the box" instance allocator implementations could be exported via the
wasmtimecrate and thus considered stable as their only public API surface are their constructors.We generally don't expect users to implement the trait themselves as it requires a lot of internal runtime understanding to do so, but we do want an easy mechanism for users to swap out the allocator implementations easily using the public Wasmtime API.
peterhuene edited a comment on Issue #5:
What if we kept the sole
InstanceAllocatortrait inwasmtime_runtimewhere it would inherently be unstable (and thus implementors would know that their implementations are subject to breaks inwasmtime_runtime) but we would then considerConfig::with_instance_allocatorto itself be stable despite takingArc<dyn wasmtime_runtime::InstanceAllocator>as an argument? Thewasmtimecrate and any implementors ofInstanceAllocatormust agree on the definition anyway, right?The "out of the box" instance allocator implementations could be exported via the
wasmtimecrate and thus considered stable as their only public API surface are their constructors.We generally don't expect users to implement the trait themselves as it requires a lot of internal runtime understanding to do so, but we do want an easy mechanism for users to swap out the allocator implementations using the public Wasmtime API.
fitzgen commented on Issue #5:
If we don't expect anyone else to implement this trait, then we might as well make it an
enumat thewasmtimeAPI level, and not expose its guts, types, and implementation details. This would let us write the instance pool in its own (internal) crate, preserve API stability, and avoid duplicating types.
fitzgen edited a comment on Issue #5:
If we don't expect anyone else to implement this trait, then we might as well make it an
enum InstanceAllocationStategy { Default, Pool }at thewasmtimeAPI level, and not expose its guts, types, and implementation details. This would let us write the instance pool in its own (internal) crate, preserve API stability, and avoid duplicating types.
peterhuene commented on Issue #5:
I can get behind that. We could always extend any such enumeration for
Customif a trait is needed in the future.
peterhuene commented on Issue #5:
I've updated the RFC with an enum approach that hides the implementation details from the
wasmtimecrate.
Last updated: Dec 06 2025 at 06:05 UTC