2 ms·
Rayon has relatively small overhead, but that doesn't mean you can find'n'replace iter() with par_iter(): - not every collection/combination of iterators suppo
by pornel 8y ago
Rayon has relatively small overhead, but that doesn't mean you can find'n'replace iter() with par_iter():
- not every collection/combination of iterators supports parallel work. For some it doesn't make sense, for some it's just not implemented.
- while Rust prevents data races, it can't prevent deadlocks, so you need to be mindful of locks.
- .iter() is allowed to mutate state outside of the iterator and use non-thread-safe objects, but .par_iter() isn't (without explicit synchronization primitives). So par_iter() will force you to use more expensive atomic and mutex-locked objects.
For data-bound problems most of the time it just works great. I've ran into problems with some networking libraries having global state, which prevented use of par_iter() (but no crashes - caught at compile time!)