wasmtime: Cache VMFuncRef in component::Func - #14189
Open
adamrk wants to merge 2 commits into
Open
Conversation
A core `Func` caches a raw pointer to its `VMFuncRef`, but a `component::Func` rederives the pointer on ever call and this contributes to host -> wasm component function calls having significantly higher overhead than core function calls (even concurrency support disabled). This PR caches the `VMFuncRef` for `component::Func` in the same it is currently done for core `Func`. The `VMFuncRef` for the associated `post_return` call is also cached along with Some additional metadata. These are my benchmark results for the impact on nop calls with no arguments or return values: Before change: | Call type | Latency | ----------------------------------------------- | core | 35 ns | | component (concurrency disabled) | 300 ns | | component (concurrency enabled) | 800 ns | After change: | Call type | Latency | ----------------------------------------------- | core | 35 ns | | component (concurrency disabled) | 140 ns | | component (concurrency enabled) | 600 ns | The bencmarks run are: ``` cargo bench --bench call -- --exact "sync/no-hook/core - host-to-wasm - typed - nop" cargo bench --bench call -- --exact "no-concurrent/sync/no-hook/component - host-to-wasm - typed - nop" cargo bench --bench call -- --exact "concurrent/sync/no-hook/component - host-to-wasm - typed - nop" ```
adamrk
requested review from
alexcrichton and
pchickey
and removed request for
a team
August 21, 2026 19:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A core
Funccaches a raw pointer to itsVMFuncRef, but acomponent::Funcrederives the pointer on ever call and thiscontributes to host -> wasm component function calls having
significantly higher overhead than core function calls (even concurrency
support disabled).
This PR caches the
VMFuncRefforcomponent::Funcin the same it iscurrently done for core
Func. TheVMFuncReffor the associatedpost_returncall is also cached along with Some additional metadata.These are my benchmark results for the impact on nop calls with no
arguments or return values:
Before change:
After change:
The bencmarks run are:
A separate commit also modifies the
callbenchmark to allow running component calls without concurrency support.