Stream: wasmtime

Topic: What does Func->post_return does?


view this post on Zulip Sehz (Mar 23 2024 at 00:06):

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.

view this post on Zulip Alex Crichton (Mar 23 2024 at 03:09):

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?

view this post on Zulip Karel Hrkal (kajacx) (Mar 23 2024 at 16:39):

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.

view this post on Zulip Sehz (Mar 23 2024 at 17:16):

does it still needed If I am invoking same function? this seems to be error prone. I am invoking same function many times repeatedly

view this post on Zulip Sehz (Mar 23 2024 at 17:20):

I guess, why not call invoke object cleaning in fun call so this is invisible to API.

view this post on Zulip Alex Crichton (Mar 24 2024 at 17:09):

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