Rust-Based, Memory-Safe PNG Decoders "Vastly Outperform" C-Based PNG Libraries

Written by Michael Larabel in Programming on 9 December 2024 at 09:05 AM EST. 186 Comments
PROGRAMMING
Video and image encoders/decoders written in the Rust programming language for its memory safety guarantees is often viewed as one of the compelling areas for the programming language to better protect against malformed/malicious content especially within web browsers. Not only are Rust-based PNG image decoders proving to be more secure than C-based decoders, but the performance of the Rust solutions can be even faster.

Sergey Davidoff with the image-png and zune-png Rust projects shared that the team posted to Reddit some promising details around their own findings for memory-safe Rust PNG decoders being able to outperform common C PNG libraries by a significant margin.

The developers posted their findings in a Reddit post and commented:
"Memory-safe implementations of PNG (png, zune-png, wuffs) now dramatically outperform memory-unsafe ones (libpng, spng, stb_image) when decoding images.

Rust png crate that tops our benchmark shows 1.8x improvement over libpng on x86 and 1.5x improvement on ARM."

The speedy performance does still depend upon architecture-specific SIMD optimizations so your mileage may vary. For the benchmarks posted on Reddit, they were using an AMD Zen 4 system.

In addition to being faster and more secure than the C-based PNG libraries, they also argue that these Rust-based solutions are production ready:
"Is this production-ready?

Yes!

All three memory-safe implementations support APNG, reading/writing auxiliary chunks, and other features expected of a modern PNG library.

png and zune-png have been tested on a wide range of real-world images, with over 100,000 of them in the test corpus alone. And png is used by every user of the image crate, so it has been thoroughly battle-tested.

WUFFS PNG v0.4 seems to fail on grayscale images with alpha in our tests. We haven't investigated this in depth, it might be a configuration issue on our part rather than a bug. Still, we cannot vouch for WUFFS like we can for Rust libraries."

It will be interesting to see how the adoption of Rust-based PNG implementation goes over the coming years along with other Rust-based image/video encoders and decoders.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week