image-rs / jpeg-decoder

JPEG decoder written in Rust
Apache License 2.0
150 stars 87 forks source link

Multithreading is not used for IDCT if the `rayon` feature is enabled #245

Open Shnatsel opened 2 years ago

Shnatsel commented 2 years ago

hyperfine shows the image decoding being significantly faster with the rayon feature disabled:

Benchmark 1: jpeg-bench/target/release/jpeg-bench "some-large-jpeg.jpg"
  Time (mean ± σ):     705.5 ms ±  22.7 ms    [User: 830.4 ms, System: 151.0 ms]
  Range (min … max):   680.5 ms … 742.2 ms    10 runs

Benchmark 2: jpeg-bench-parallel/target/release/jpeg-bench-parallel "some-large-jpeg.jpg"
  Time (mean ± σ):     867.2 ms ±  11.1 ms    [User: 906.7 ms, System: 120.5 ms]
  Range (min … max):   854.6 ms … 888.7 ms    10 runs

Summary
  'jpeg-bench/target/release/jpeg-bench "some-large-jpeg.jpg"' ran
    1.23 ± 0.04 times faster than 'jpeg-bench-parallel/target/release/jpeg-bench-parallel "some-large-jpeg.jpg"'

Looking at the profile, it seems that the additional threads for IDCT are spawned only when the rayon feature is disabled (profile). When it is enabled, the IDCT is happening on the main thread (profile).