Is post_return https://docs.rs/wasmtime/latest/wasmtime/component/struct.Func.html#method.post_return required after calling function? This seems take considerable amount of time.
If no further functions are used on a component, no, it can be omitted. If another function is going to be invoked, yes, it is required.
Can you clarify why it's taking a considerable amount of time? Or do you have an example we could perhaps profile and try to optimize?
I think it gives the guest an opportunity to destroy the returned object after the host has read it's contents. If you are returning a complex object, it's address is returned and the host reads the data at that address and then the guest destroys the object (explicitly in Rust/C/C++, dropping a reference to in GC languages) in the post-return call, since the host cannot know how the guest manages it's memory. Or at least I think this is how it works.
does it still needed If I am invoking same function? this seems to be error prone. I am invoking same function many times repeatedly
I guess, why not call invoke object cleaning in fun call so this is invisible to API.
Karel is correct, that's what post-return
enables at the ABI level. At the API level splittng out post_return
from call
enables WasmStr
and WasmList
types to exist which borrow directly from linear memory. With post_return
bundled in they couldn't exist.
I'll note that with bindgen!
-generated APIs post_return
happens automatically, so if you don't want to worry about post-return I'd recommend using those APIs instead
Last updated: Nov 22 2024 at 16:03 UTC