Four crates here, which is the fastest? Basically I would like to just use wasm and the js part is just for interfacing with wasm processes. in this sense, which is the fastest one to work with?
I saw a lot of raw wasm_bindgen things but not sure what it means.
js_sys
wasm_bindgen
wasm_bindgen_futures
web_sys
Why 4 and not just 2? e.g. wasm_bindgen_futures and web_sys seems to be good enough?
Do you mean the "fastest" as in development time or runtime performance?
If you mean runtime, you will basically always have to use the wasm_bindgen crate so that's a given.
As for wasm_bindgen_futures, js_sys, and web_sys if you want to be really performant you should write as much as you can in pure Rust and do as little interfacing between JS / wasm as you can - since there's always a cost to doing FFI. Because web_sys and js_sys make JS APIs available inside Rust, they aren't going to be as fast as writing those same APIs in just JS.
Why 4 and not just 2? e.g. wasm_bindgen_futures and web_sys seems to be good enough?
wasm_bindgen_futures is a crate that helps you use promises from inside Rust. You'd still need to use it and wasm_bindgen.
roughly what's the cost of FFI from js / wasm? in request per second kind of performance overhead.
i believe using wasm for crypto / blake2b kind of number crunching is worth the extra work but in general, what should I expect from doing js/wasm or just js?
what's worth the time to write in rust->wasm just for js calling?
@gitmko0 Each crate has a different purpose, but they are all designed to work together:
wasm-bindgen contains the core functionality for sending values between JS and Rust. This crate is mandatory.
wasm-bindgen-futures contains functionality for running async code. This crate is only needed if you're using Futures.
js-sys contains type definitions for the built-in JS types (such as Date, Array, Object, etc.). This crate is only needed if you need to use those types.
web-sys contains type definitions for all of the web APIs (such as the DOM). This crate is only needed if you need to use those APIs.
All of the crates use wasm-bindgen, because wasm-bindgen contains the core functionality which is needed for using JS code.
It's normal in Rust to have small crates which do one thing, which is why the functionality is split into different crates.
roughly what's the cost of FFI from js / wasm? in request per second kind of performance overhead.
You need to be more specific, since the cost will vary depending on the types and operations that you're doing. But you can always just benchmark it yourself to see what the performance is for your code.
what's worth the time to write in rust->wasm just for js calling?
That will depend on your program, so you have to benchmark it to see. But in general Rust is very fast, and the communication between JS and Rust is also usually very fast, which is why Rust DOM frameworks can be faster than React/Angular/etc.
Most helpful comment
@gitmko0 Each crate has a different purpose, but they are all designed to work together:
wasm-bindgencontains the core functionality for sending values between JS and Rust. This crate is mandatory.wasm-bindgen-futurescontains functionality for running async code. This crate is only needed if you're using Futures.js-syscontains type definitions for the built-in JS types (such asDate,Array,Object, etc.). This crate is only needed if you need to use those types.web-syscontains type definitions for all of the web APIs (such as the DOM). This crate is only needed if you need to use those APIs.All of the crates use wasm-bindgen, because wasm-bindgen contains the core functionality which is needed for using JS code.
It's normal in Rust to have small crates which do one thing, which is why the functionality is split into different crates.
You need to be more specific, since the cost will vary depending on the types and operations that you're doing. But you can always just benchmark it yourself to see what the performance is for your code.
That will depend on your program, so you have to benchmark it to see. But in general Rust is very fast, and the communication between JS and Rust is also usually very fast, which is why Rust DOM frameworks can be faster than React/Angular/etc.