Skip to main content

on_band_pool

Function on_band_pool 

Source
fn on_band_pool<R: Send>(bands: usize, convert: impl FnOnce() -> R + Send) -> R
Expand description

Run convert, a conversion’s parallel bands, on a pool of bands threads: one a band count, built the first time a conversion asks for it and kept for the process.

rayon’s global pool has a thread per CPU. Handed a frame’s bands, it also wakes the threads it has no band for, and those spin before they sleep again, a cost that grows with the CPUs rather than the bands. On a pool of as many threads as bands, each thread takes a band. Where the pool cannot be built, or bands is over MAX_POOLED_BANDS, the bands run on the global pool.

A conversion called on a rayon pool’s thread keeps to that pool: the forked child that encodes_in_child probes an encoder in installs one, since a pool built before the fork has no threads in the child.