Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow data transfer bandwidth (80MB/s) when passing data from host to WASM function in Wasmedge #3408

Open
wenzhaojie opened this issue May 17, 2024 · 3 comments
Labels
question Further information is requested

Comments

@wenzhaojie
Copy link

wenzhaojie commented May 17, 2024

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

wasm_bindwidth.zip

Results:
% ./wasm_bindwidth rust_bindgen.wasm
bindwidth: 83.205145 MB/s

Appendix

wasmedge 0.13.4

@wenzhaojie wenzhaojie added the question Further information is requested label May 17, 2024
@hydai
Copy link
Member

hydai commented May 20, 2024

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.

@wenzhaojie
Copy link
Author

wenzhaojie commented May 20, 2024

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.

@hydai
Copy link
Member

hydai commented May 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants