Stream: general

Topic: How many memory copy happens when a struct passing to guest?


view this post on Zulip Bryton (Feb 28 2024 at 03:13):

In component mode, How many memory copy happens when a struct passing from host to guest? Host side data type to wit type(repl(c)), wit type lower to guest linear memory (or return area), from linear memory (or return area) to guest stack local variable type. Is my understanding correct? Thanks for your guidance.

view this post on Zulip Christof Petig (Feb 28 2024 at 06:55):

In my understanding with a list you can get down to zero copies if you design carefully: allocate in linear memory, construct members in place and pass ownership to guest. This assumes that you only have a single definition of the type of course as any change of types will involve a conversion.

With small structs by value canonical ABI optimizes by passing the struct members as direct function arguments. And for larger ones (more than 16 integers up to 64 bit) the passing in linear memory makes a copy you can't avoid for now.

view this post on Zulip Bryton (Feb 28 2024 at 13:44):

Thank you very much, Christof. Do you have any idea to get linear memory from wamstime::component? I don't think it is supported by wasmtime for now.

view this post on Zulip Bryton (Feb 28 2024 at 13:45):

Otherwise, we can not construct members in place from linear memory.

view this post on Zulip Bryton (Feb 28 2024 at 13:48):

Another concern is that WASM component hides the data struct underlying layout from different languages, directly construct members in place maybe conflict with this concept?

view this post on Zulip Lann Martin (Feb 28 2024 at 14:12):

Arguments are stored according to the component model canonical ABI; each guest language is responsible for producing/consuming this standard layout.

view this post on Zulip Lann Martin (Feb 28 2024 at 14:15):

I think you are correct that the wasmtime API does not currently expose components' modules' linear memories, at least not in any documented/stable way.

view this post on Zulip Bryton (Feb 28 2024 at 14:25):

I see. Do you have any suggestion to pass large data struct to guest? In my case, I have many large data structs.

Besides, would be it reasonable for WASM component mode to leave chance to let passing large data structs through linear memory? Like mmap for data sharing between user and kernel space. I really think it does matter to WASM performance.

view this post on Zulip Alex Crichton (Feb 28 2024 at 16:19):

The discussion over here is perhaps of interest you as I think it touches some related topics


Last updated: Oct 23 2024 at 20:03 UTC