When designing a WIT based API for a publisher subscriber scheme at AUTOSAR we came across the problem how to model single producer multiple consumer (with zero copy).
While I perfectly understand that full zero copy needs support from the host side, being able to express that the result of a host call has a specific structure (potentially containing lists and strings) but shouldn't be freed by the guest would help a lot. Basically returning a borrow<record-type>
would be my preferred solution.
I can work around this by returning pointers or opaque resources but then I lose the easy language interoperability provided by WIT.
I think the closest you will get will be approximating records with resource getters/setters
You could potentially roll your own via multi-memories, but as you say that would require some host work and you'd be on your own for safety
Lann Martin said:
I think the closest you will get will be approximating records with resource getters/setters
But then to avoid creating copies I would need to repeat the procedure for any lists/strings returned from the getter, wouldn't I.
[I have seen the stringref proposal which seems to solve a similar problem]
This is a neat idea, and I talked about it with a few people last fall at CN Wasm Day. I think it would be a useful tool to have (if we could figure out what the resource API for each value type should be) but even if we did decide to do something like this it would be a while before we could get started on it because we only have so many resources working on the Component Model and we need to focus on things like building up resources and finalizing/implementing the structured concurrency model.
I originally proposed it with the hope of reducing/avoiding copying the arguments passed to Wasm User-Defined Functions in SQL databases.
Kyle Brown said:
This is a neat idea, and I talked about it with a few people last fall at CN Wasm Day. I think it would be a useful tool to have (if we could figure out what the resource API for each value type should be) but even if we did decide to do something like this it would be a while before we could get started on it because we only have so many resources working on the Component Model and we need to focus on things like building up resources and finalizing/implementing the structured concurrency model.
I can already start supporting it for c++ and Rust if we agree that it is the right direction, I would guess that a read only reference would be the right api and the abi would be identical to the owned case without the transfer of ownership (aka freeing of the list, string, etc after use)
And likely just implementing it in the ABI code might already cover some more languages.
Borrowed value types would require Component Model and Canonical ABI specification that would need to be discussed and implemented there first.
I also only talked about it with a few people, so it's far from having a consensus emerge that its the right way to go.
Last updated: Dec 23 2024 at 12:05 UTC