Rayon
Here we’ll look into how to make best use of Rayon in a Tauri app. And before you ask, the reason you’d want to mix in Rayon when you already have Tokio in your Tauri app is because Tokio runs concurrently, Rayon runs in parallel. Which oversimplified means that if you run something big, heavy and blocking in Tokio you’ll be preventing other work from progressing since tasks run in a cooperative manner, while in Rayon all threads are assholes that just care about themselves.
Tokio for I/O bound tasks.
Rayon for CPU bound tasks.
You can also configure the threadpool for Rayon, though I wouldn’t recommend it, you’ll most likely make it better on your machine and worse for everyone else.
Instead of using boring old synchronous iterators, lets make them parallel with Rayon. Just replace .iter()
with par_iter()
and presto, your synchronous task is now fully parallel.
If you don’t want to make use of the global threadpool you can make a temporary local threadpool for use in a specific task.