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>?
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
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
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.
Alex Crichton said:
Otherwise though, if you're willing to break out the
unsafe, you can always implement theComponentTypeandLowertraits 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
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