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.
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.
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.
Otherwise, we can not construct members in place from linear memory.
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?
Arguments are stored according to the component model canonical ABI; each guest language is responsible for producing/consuming this standard layout.
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.
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.
The discussion over here is perhaps of interest you as I think it touches some related topics
Last updated: Nov 22 2024 at 16:03 UTC