Slow data transfer bandwidth (80MB/s) when passing data from host to WASM function in Wasmedge
wenzhaojie opened this issue · comments
Summary
When invoking functions in a WebAssembly module using Wasmedge and passing data, especially strings, from the host function to the WASM function, there seems to be a significant slowdown in data transfer speed. I have implemented a host function in Go language, which calls a function from the WASM module. This function receives a string as a parameter and immediately returns the same string. Since Wasmedge does not support passing strings directly, I am using the method of wasmedge-bindgen instead.
Steps to Reproduce
cd rust_bindgen
cargo build --target wasm32-wasi --release
cp target/wasm32-wasi/release/rust_bindgen.wasm ../
cd ..
go build wasm_bindwidth.go
./wasm_bindwidth rust_bindgen.wasm
Results:
% ./wasm_bindwidth rust_bindgen.wasm
bindwidth: 83.205145 MB/s
Appendix
wasmedge 0.13.4
I believe the reason is that the memory layout inside Wasm is totally different from Golang. So, when swapping the data, we have to do some memory copy or layout conversion between Wasm and Golang. It will take time and have lots of costs.
I believe the reason is that the memory layout inside Wasm is totally different from Golang. So, when swapping the data, we have to do some memory copy or layout conversion between Wasm and Golang. It will take time and have lots of costs.
@hydai Ah, that could be the reason. Do you believe other WebAssembly runtimes such as wasmtime or wasmer might yield better performance? Additionally, do you happen to know which language SDK would offer the optimal performance? Rust SDK, perhaps? Or C? Thank you very much for your response.
Do you believe other WebAssembly runtimes such as wasmtime or wasmer might yield better performance?
You can do the benchmark for this :-)
Additionally, do you happen to know which language SDK would offer the optimal performance? Rust SDK, perhaps? Or C? Thank you very much for your response.
If you want to handle the complex types between other languages and Wasm, you may need to wait for the Component Model proposal to be merged into the Wasm spec. It provides a unified way to avoid such things.
The question is answered. Closing this.