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

Inconsistent behaviour with `find_any` #17

Closed danitrod closed 3 years ago

danitrod commented 3 years ago

When using .find_any or .find_map_any on a ParallelIterator, I expected my main worker to have the first found value returned as soon as one of the workers found it and stop searching (which does happen running Rayon conventionally). However, the main worker waits for a result on every worker to stop searching. Below a screen shot of my application logs to better clarify - I am searching with a range divided between threads, and the main thread always waits until every worker finished searching to proceed. I wanted it to finish once I had the first result.

Screen Shot 2021-10-12 at 16 16 21

Happy to provide more details on my application if needed.

Perhaps this is a too specific issue that needs to be handled directly in Rayon? Not sure

RReverser commented 3 years ago

Can you provide code example as well as logs from "running Rayon conventionally"? It's hard to tell what's going on, but some extra info could help to narrow it down.

In theory, it should be purely Rayon issue as we don't really do anything special except spawning threads, so I'm surprised there is some difference between platforms.

danitrod commented 3 years ago

Sure thing, I'm trying to produce a minimal example to share

danitrod commented 3 years ago

Looks like this is my mistake, I misunderstood the way find_any actually works. It doesn't stop any already running search, just stops the par_iterator from returning more elements when a value is found. Running conventionally actually does result in the same behaviour, I just wasn't logging in the same way. Sorry if this caused any trouble.

RReverser commented 3 years ago

Ah glad you found the root cause.