The zlib-rs compression library, developed in Rust by the Trifecta Tech Foundation, has become the fastest known zlib-compatible implementation for decompression, surpassing even high-performance C projects like zlib-ng and zlib-chromium.

Version 0.4.2 of zlib-rs introduces key performance enhancements that position this library at the forefront of the compression ecosystem. With a focus on memory safety and advanced SIMD support, zlib-rs proves that Rust can offer not only security but also superior speed compared to long-standing C-based libraries.

The foundation has published a comprehensive performance dashboard comparing its main development branch with other implementations, while tracking historical progress to avoid regressions.


Decompression: Leading the Field

In benchmark tests against zlib-ng — one of the most optimized C-based libraries — and zlib-chromium, zlib-rs consistently outperforms from 32-byte blocks and up. For realistic scenarios (between 1 KB and 64 KB input chunks), the results are decisive: over 10 % performance gains against zlib-ng in many cases and steady advantages over zlib-chromium in mid- to large-size chunks.

The key lies in dynamic multiversioning: a runtime technique that selects the optimal function implementation depending on the SIMD capabilities of the user’s CPU. This approach ensures maximum compatibility and performance without recompilation.

Additionally, support has been added for DFA jump threading, an LLVM optimization proposed by developer Nikita Popov that boosts performance in finite-state machine logic — especially relevant for streaming decompression where data arrives in small fragments.


Compression: Promising Progress

While most of the current focus is on decompression, zlib-rs is also advancing in compression tasks. Compared to zlib-ng, performance is mixed, but with notable wins: a 13 % improvement at the highest compression level (level 9) and over 6 % gain at the default level (6).

There is still room for optimization at low and mid compression levels. The team, with contributions from developer Brian Pane, is actively working to close this gap.


Integration for Rust and C Projects

zlib-rs is compatible with both Rust and C projects:

  • In Rust, the recommended method is to use the flate2 crate version 1.1.0 with the zlib-rs feature enabled, allowing seamless adoption.
  • In C, it can be compiled as a dynamic library compatible with the traditional zlib API (libz), making it easy to integrate into both legacy and modern projects.

Although zlib-rs already covers most expected functionality, some lesser-used API functions related to .gz files are still under development. To complete this work and enhance packaging and performance, the Trifecta Tech Foundation is seeking funding of €95,000. A detailed workplan is available.


A Step Forward in Security and Performance

Migrating from C-based libraries to Rust-based alternatives like zlib-rs addresses a critical need: eliminating memory vulnerabilities in widely used software components. Part of the foundation’s data compression initiative, the project aims not only to be faster but also safer and more sustainable.

With cross-platform support, runtime SIMD adaptation, and a transparent open-source development model, zlib-rs proves that decades of C development can be surpassed by modern, efficient, and secure architecture.

Reference: zlib-rs is faster than C

Scroll to Top