-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Borrowing non-resource types #473
Comments
I suspect there's some confusion due to the use of Rust's "borrowing" terminology. In Rust a "borrow" is generally implemented as a pointer to some memory. In the Component Model, "borrows" only apply to Resources, which from the components POV are just an opaque index into an table maintained by the host - out of reach from the guest. Similar to file descriptors in POSIX.
That's right. It's not possible to hand out direct memory references between components due to the shared nothing architecture, which is a pillar of the CM design and enabler for many other key features like sandboxing and "colorblind" async.
I'll defer to Luke for the definitive answer here, but I guess: No. If a particular parameter is too large to copy around between components at once, maybe |
Agreed with @badeend that the main challenge with borrowing values in memory is that when the caller and callee are both wasm components, the callee necessarily has a disjoint linear memory from the caller and thus some sort of copy is necessary today. However, when the receiver of a value is the host, since the host can always see all of wasm's linear memory, even the plain function But for achieving zero-copy in component-to-component scenarios, I think the following 2 steps are promising:
Lots of hypotheticals in there, and nothing imminent, but I thought I'd share the new ideas. |
Hi, thank you for the answers and sorry about the late response. The design decision now makes a lot of sense. The heaps are disjoint to enforce isolation.
Are there any example yet of how to use streams and futures, or are these features not yet available? I found https://www.fermyon.com/blog/looking-ahead-to-wasip3 so far which shows how to use wasm components with HTTP. |
Streams and futures are part of the async support being developed in this repo and incrementally upstreamed to the main Wasmtime repo. There aren't many examples yet besides what's in that blog post, but there are some tests you can look at, e.g.:
Both the implementation and the spec are still evolving, so I don't recommend doing anything serious with them yet, but feel free to experiment and provide feedback! |
Currently, resource types can be passed to a wasm component by reference with
borrow<...>
:According to the documentation, it is not possible to pass non-resource types by reference. Are there any plans of adding this feature? I found the repo https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md, but it seems to be archived.
I am using wasm components to implement filters for streaming applications and it would be nice if the filter could take the data by-reference to avoid copying:
The text was updated successfully, but these errors were encountered: