rayon-rs / rayon

Rayon: A data parallelism library for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

general purpose WASM support?

fr-an-k opened this issue · comments

I tried to build the example as wasm32-unknown-unknown but it requires the js feature.
There is no browser API or wasm-bindgen in a general purpose WASM module.

It would be nice if this would also be supported, or a mention that it will not be supported and why.

In my case I will probably just use rayon normally for native functions that invoke a WASM function.
So the WASM function just handles one job and returns when done.
The native function is wrapped and threaded by Rayon as usual.
Perhaps that's how it should be done.

For web and native compatibility on the same WASM modules, I would probably have to compile the wasm modules using wasm-bindgen-rayon and not use those exports on a native runtime.

It's difficult to get your head around these things so it would be nice to have this explained or demonstrated for everyone.

This also relates to the issues linked here: #93

Rayon can't fully run in general wasm32-unknown-unknown because there's no threading support. We do at least have a single-threaded fallback, so code written with rayon can still work for the most part, but you don't need to do any special setup for that.

If rayon is running natively, then it's orthogonal that the workload may be a wasm module. Rayon won't know anything about it, but you'll need to load the module to run in whatever wasm runtime you've chosen, just as you would if rayon wasn't involved at all.