r/C_Programming • u/KanatoreIT • 11h ago
SOVDEFLATE: A zero-dependency DEFLATE/ZLIB/GZIP engine written from scratch in C11 with AVX2, BMI2, and AVX-512 VNNI
https://github.com/KanatoreIT/SOVDEFLATEHi everyone,
I’ve been working on SOVDEFLATE, an in-house DEFLATE (RFC 1951), ZLIB (RFC 1950), and GZIP (RFC 1952) compression and decompression library written from scratch in C11 with zero third-party dependencies (only the C standard library and OS thread APIs).
Repository: https://github.com/KanatoreIT/SOVDEFLATE
Key technical details:
- Runtime SIMD dispatch: Selects between scalar baseline, BMI2, AVX2, and 256-bit AVX-512 VL + VNNI (for Adler-32) at startup.
- PDF stream handling: Includes sovdeflate_decompress_prefix and an incremental decoder that stops cleanly at the end of a stream without consuming or rejecting trailing bytes (like \nendstream in PDFs), reporting exact bytes consumed.
- Damaged stream recovery: Recovers partial bytes from corrupted streams matching zlib behavior (tested across 11,982 damaged streams).
- Optional C++20 header-only wrapper (sovdeflate_cpp20.hpp) and custom memory allocator with byte limits.
Honest benchmarks (2,000 real DocLayNet PDFs / 445.5 MB uncompressed, i5-11400H):
- Decompression (1 thread): 713 MB/s (vs. 738 MB/s in libdeflate 1.26 — about 3.5% behind).
- Decompression (12 threads): 5,310 MB/s (vs. 6,037 MB/s in libdeflate 1.26).
- Compression (DEFAULT / level 6): 77.7 MB/s at 1.000× size (vs. 46.8 MB/s in zlib 1.3.2 and 127.2 MB/s in libdeflate).
Compression speed is still behind libdeflate and is my main focus for the next iteration. The repo also includes an originality audit script checking against zlib, zlib-ng, libdeflate, miniz, and stb, plus ASan/UBSan test scripts.
I’d love to hear any feedback on the C11 implementation, SIMD paths, or ideas to close the compression speed gap!
•
u/mikeblas 11h ago
How was AI involved in the creation of your project?