Repository navigation
Description
Function calls copy byte and string arguments more often than they need to.
Problem
callandcall_hosttake arguments by value. A caller that holds a&stror&[u8]must clone it first, even though the call only reads it.- A function can receive bytes as
Vec<u8>orVec<Bytes>. In the guest,Vec<u8>joins the transport buffers into a new vector andVec<Bytes>does not. The cost is hidden in the receiver's signature.
Proposal
Callers pass borrowed values. Functions take and return bytes only as Vec<Bytes>.
| Arguments | Parameters and return types | |
|---|---|---|
| Scalars | i32, u32, i64, u64, f32, f64, bool |
same, plus () as a return type |
| Strings | &str |
String |
| Bytes | &[u8], &[u8; N], &[Bytes] |
Vec<Bytes> |
Arguments are what callers pass to call, call_host and #[host_function] stubs. Parameters and return types are what #[guest_function] and host functions declare.
Breaking changes
- Owned
String,Vec<u8>,BytesandVec<Bytes>are no longer accepted as arguments. Passs.as_str(),&vor&chunks. Vec<u8>is no longer a parameter or return type. UseVec<Bytes>.concat()joins the chunks when a function needs one contiguous buffer.
These are hard breaks, but each fix is a one-line change at a call site or a function signature, and the compile error names it.
Effect
Copies per byte argument, host to guest:
| Caller holds | Guest parameter (today) | Today | After |
|---|---|---|---|
Vec<u8> |
Vec<u8> |
2 | 1 |
&[u8] |
Vec<u8> |
3 | 1 |
&[u8] |
Vec<Bytes> |
2 | 1 |
Vec<Bytes> |
Vec<Bytes> |
1 | 1 |
After the change, every byte argument takes one copy: the host writes it into the guest's transport buffers, and the guest reads it from them in place. Guest-to-host calls save the caller's clone. The host still copies guest data once before reading it, for safety.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
[-]Allow host to pass reference types (&[u8] and &str) to guest funcs[/-][+]Borrow function arguments and use one byte type[/+]ludfjig commentedon Nov 9, 2026
Let's wait for serde+postcard pr and streams pr for this