Stream: wasmtime

Topic: How to access the memory of a component


view this post on Zulip Antoine Lavandier (Oct 15 2025 at 13:57):

With modules, you can access the linear memory with Instance::get_memory(). component::Instance doesn't have a similar method. What is the preferred way to access the memory directly ?

view this post on Zulip Joel Dice (Oct 15 2025 at 14:07):

A component is a "shared-nothing" abstraction, meaning there's no way for it to export a memory, table, or global variable, nor is there a way to access any of those things directly using Wasmtime's API. You can pass e.g. list<u8> objects to and from the component when calling exported functions, or use a stream<u8> to stream bytes asynchronously (which gives you temporary access to the subset of guest memory being read from or written to), but there's no way to get access to an entire memory at once.

If you can elaborate on what you're trying to do, we might be able to give you more specific advice.

view this post on Zulip Antoine Lavandier (Oct 15 2025 at 14:37):

The big picture is that I want to build a GET/POST/PUT type service where requests concerning certain URIs are dealt with by a component. To that end, when said URIs appear, I want to write the request's payload directly in the component's linear memory to avoid the unnecessary copying that comes from using list<u8>. IIUC, having a back and forth with list<u8> would mean using 3 or 4 dynamic allocations every time (2 in the Host, 1 or 2 in the Guest) when really only 1 or 2 allocations (in my case they could probably even be static) in the Guest are needed.

I haven't tried streams because I thought that they required std/ wasi to function but that perhaps isn't true. I'm using wasmtime on embedded devices so no_std is required.

view this post on Zulip Ramon Klass (Oct 15 2025 at 14:39):

what you are describing is only possible with modules (wasip1 or wasm), components force you into sending list<u8> etc

view this post on Zulip Joel Dice (Oct 15 2025 at 14:43):

Antoine Lavandier said:

I haven't tried streams because I thought that they requires std/ wasi to function but that perhaps isn't true.

streams don't require WASI, but they do currently require std. Theoretically, we could probably make the host implementation no-std-compatible, though. I do suspect using a stream<u8> would be most optimal for your case, since it allows you to write directly to the guest memory.

view this post on Zulip Antoine Lavandier (Oct 15 2025 at 14:46):

Joel Dice said:

streams don't require WASI, but they do currently require std. Theoretically, we could probably make the host implementation no-std-compatible, though. I do suspect using a stream<u8> would be most optimal for your case, since it allows you to write directly to the guest memory.

Where does that implementation lie in the Wasmtime repo ? If it's something I can reasonably understand I wouldn't be against participating in making it no_std compatible

view this post on Zulip Joel Dice (Oct 15 2025 at 14:59):

https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/runtime/component/concurrent.rs and the various submodules under https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasmtime/src/runtime/component/concurrent, most notably futures_and_streams.rs. There's a lot of code, and it's not easy to wrap your head around, but I imagine implementing no_std support wouldn't require deep understanding; just changing the use statements from std to core or alloc as appropriate, and maybe adding some #[cfg(...)] attributes to any features that really require std (I don't know of any offhand).

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime
A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

Last updated: Dec 06 2025 at 06:05 UTC