image-rs / image-png

PNG decoding and encoding library in pure Rust
https://docs.rs/png
Apache License 2.0
347 stars 139 forks source link

Parallel image encoding #478

Open fintelia opened 4 months ago

fintelia commented 4 months ago

Adds a feature flag (rayon) that enables parallel encoding of PNGs. This drastically reduces the time taken to encode a single image. With target-cpu=native, my 6 core/12 thread CPU is able to exceed 1 billion pixels/second encoding speed on the QOI benchmark suite:

                                              Ratio             Encode
---------                                    -------     --------------------
Single-threaded                              27.861%     245 mps  0.829 GiB/s
Single-threaded (target-cpu=native)          27.861%     308 mps  1.042 GiB/s

Parallel                                     27.861%     917 mps  3.099 GiB/s
Parallel (target-cpu=native)                 27.861%    1084 mps  3.664 GiB/s

Depends on https://github.com/image-rs/fdeflate/pull/23.

Shnatsel commented 2 months ago

FWIW https://crates.io/crates/mtpng exists and can be used as inspiration/reference