alexcrichton opened PR #3294 from less-hostcall-alloc
to main
:
This commit improves the runtime support for wasm-to-host invocations
for functions created withFunc::new
orwasmtime_func_new
in the C
API. Previously aVec
(sometimes aSmallVec
) would be dynamically
allocated on each host call to store the arguments that are coming from
wasm and going to the host. In the case of thewasmtime
crate we need
to decode theu128
-stored values, and in the case of the C API we need
to decode theVal
into the C API'swasmtime_val_t
.The technique used in this commit is to store a singular
Vec<T>
inside
the "store", be it the literalStore<T>
or within theT
in the case
of the C API, which can be reused across wasm->host calls. This means
that we're unlikely to actually perform dynamic memory allocation and
instead we should hit a faster path where theVec
always has enough
capacity.Note that this is just a mild improvement for
Func::new
-based
functions. It's still the case thatFunc::wrap
is much faster, but
unfortunately the C API doesn't have access toFunc::wrap
, so the main
motivation here is accelerating the C API.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bjorn3 submitted PR review.
bjorn3 created PR review comment:
mem::take(&mut self.hostcall_val_storage)
alexcrichton updated PR #3294 from less-hostcall-alloc
to main
.
alexcrichton updated PR #3294 from less-hostcall-alloc
to main
.
alexcrichton updated PR #3294 from less-hostcall-alloc
to main
.
cfallin submitted PR review.
alexcrichton merged PR #3294.
Last updated: Nov 22 2024 at 16:03 UTC