GoogleChromeLabs / wasm-bindgen-rayon

An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
https://github.com/RReverser/wasm-bindgen-rayon
Apache License 2.0
404 stars 35 forks source link

my program gets stuck when trying to do parallel iter #10

Closed ImUrX closed 3 years ago

ImUrX commented 3 years ago

I tried adding this on my wasm library, i used to make predefined ranges for each thread of the worker and wanted to see how fast wasm threads was compared to the previous method so i tried adding this and it compiles and everything but when executed in the worker, it seems the workers enter some kind of deadlock and stay there consuming cpu. im sorry if this is the wrong place

ImUrX commented 3 years ago

managed to get a panic https://pastebin.com/FW4rM6Yw

RReverser commented 3 years ago

Hmm looks like it's coming from inside wee-alloc? I'm actually not sure if wee-alloc was designed with support for Wasm threads. From a quick glance, it doesn't seem to use atomics or anything here https://github.com/rustwasm/wee_alloc/blob/master/wee_alloc/src/imp_wasm32.rs.

Perhaps try enabling this feature and see what it tells? https://github.com/rustwasm/wee_alloc/blob/master/wee_alloc/Cargo.toml#L24

Or, just disable wee-alloc and see if you still get the issue.

ImUrX commented 3 years ago

after removing wee_alloc just in case, it works but its 100 times slower than the previous solution, i think this is because of rayon but i never used rayon before Is exploring the whole range of i32 possible numbers too expensive for some reason?

RReverser commented 3 years ago

Is exploring the whole range of i32 possible numbers too expensive for some reason?

I mean... it's definitely huge range, especially when combined with random generation (which is slow by itself), but it shouldn't be slower than the serial execution on one thread anyway.

ImUrX commented 3 years ago

well, thanks for taking your time on reading the code, im gonna try later the wee_alloc feature you recommended and make an issue in there for adding wasm thread support

RReverser commented 3 years ago

Np. Sorry couldn't help more.

ImUrX commented 3 years ago

no no, thank you for helping :P