Stream: wasmtime

Topic: Optimizing `list<u8>` returns in hostcalls


view this post on Zulip Dan Gohman (May 12 2026 at 22:52):

Does Wasmtime have any options, potentially including unsafe options, for optimizing a host function that returns a list<u8>, to avoid copying the data through aVec<u8>?

view this post on Zulip Chris Fallin (May 12 2026 at 23:06):

One level up, "how to not pass list<u8> around" is why the compile-time builtins work started; it doesn't literally solve that problem of course, it would be a user-visible "handle with getByte method" API instead

view this post on Zulip Alex Crichton (May 12 2026 at 23:13):

Otherwise though, if you're willing to break out the unsafe, you can always implement the ComponentType and Lower traits yourself and do whatever you want in the internals

view this post on Zulip Joel Dice (May 12 2026 at 23:19):

In case it isn't obvious: in addition to unsafe, you'll need to use a bunch of #[doc(hidden)] stuff to implement those traits, among them LowerContext::realloc, which actually allocates memory from the guest.

view this post on Zulip Victor Adossi (May 13 2026 at 11:02):

Alex Crichton said:

Otherwise though, if you're willing to break out the unsafe, you can always implement the ComponentType and Lower traits yourself and do whatever you want in the internals

An example of this trick that might be useful to explore:

https://github.com/cpetig/wasm-shm-test

view this post on Zulip Dan Gohman (May 14 2026 at 15:48):

Thanks for the suggestions! In my use case, the data is coming from a bytes::Bytes, so I just need ComponentType and Lower impls for bytes::Bytes. I've now submitted https://github.com/bytecodealliance/wasmtime/pull/13366 to do that.


Last updated: May 26 2026 at 09:09 UTC