Stream: git-wasmtime

Topic: wasmtime / PR #3294 Avoid vector allocations in wasm->hos...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 16:59):

alexcrichton opened PR #3294 from less-hostcall-alloc to main:

This commit improves the runtime support for wasm-to-host invocations
for functions created with Func::new or wasmtime_func_new in the C
API. Previously a Vec (sometimes a SmallVec) 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 the wasmtime crate we need
to decode the u128-stored values, and in the case of the C API we need
to decode the Val into the C API's wasmtime_val_t.

The technique used in this commit is to store a singular Vec<T> inside
the "store", be it the literal Store<T> or within the T 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 the Vec always has enough
capacity.

Note that this is just a mild improvement for Func::new-based
functions. It's still the case that Func::wrap is much faster, but
unfortunately the C API doesn't have access to Func::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.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 17:01):

bjorn3 submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 17:01):

bjorn3 created PR review comment:

        mem::take(&mut self.hostcall_val_storage)

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 17:29):

alexcrichton updated PR #3294 from less-hostcall-alloc to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 17:41):

alexcrichton updated PR #3294 from less-hostcall-alloc to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 19:00):

alexcrichton updated PR #3294 from less-hostcall-alloc to main.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 19:08):

cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 20:14):

alexcrichton merged PR #3294.


Last updated: Nov 22 2024 at 16:03 UTC