LZ0 - Asymmetric LZ compressor with zero-malloc decoder
Show HN: LZ0 -An asymmetric LZ compressor with ultra minimal, 0-alloc decoder
LZ0 is a lightweight, experimental lossless compression format and C implementation that flips the script on traditional LZ compressors. Instead of balancing effort between encoding and decoding, LZ0 moves complexity to the encoder, producing a compact bitstream that an ultra-minimal decoder can unpack with zero dynamic memory allocation. The decoder is tiny (~150 lines of C, or ~40 lines in its minimal form), auditable, and easily embedded into bootloaders, microcontrollers, and kernel space. It decompresses at hundreds of megabytes per second while achieving compression ratios comparable to ZX0. The encoder uses a hash chain, SA-IS suffix array, and sparse dynamic programming to compress 5 MiB files in seconds rather than minutes. LZ0 is ideal for small-to-medium binary blobs and structured datasets where decoder simplicity and speed are paramount.
Move complexity from the decoder to the encoder.
- nellacross
I'd love to see a deeper comparison against LZ4. An LZ4-style decoder can be made minimal, and one can use LZ4HC to achieve better density without sacrificing decompression speed.
- aidenn0
Be nice to see benchmarks against lz4hc -9, since that's the closest competitor in terms of both compression speed and decompression speed.
- seb3773
I built LZ0, an asymmetric LZ compressor targeting environments where decompression resources are tightly constrained (bootloaders, microcontrollers, embedded asset loading) or where decoder simplicity matters most.
I've always admired micro-decoders like Einar Saukas' ZX0—zero dynamic allocation, no scratch RAM, and small enough to fit into a handful of instructions. The catch with traditional optimal parsers is that they often scale in O(N^2), taking tens of seconds or minutes once files exceed a few hundred kilobytes. I wrote LZ0 to keep that same decoder footprint while compressing multi-megabyte files in milliseconds.
Where it sits (Ratio vs. Speed): - Compression density: beats LZ4/Snappy, staying within 1–3% of zlib/Deflate and exhaustive ZX0. - Decompression speed: 200–350 MB/s for portable C, 250–700 MB/s for compact ASM, and 520–1,330 MB/s for vector ASM. That's up to 10x faster than Deflate while requiring zero heap memory or state tables. - Compression throughput: ~1.3–1.6 s on typical 1 MB inputs.
How the encoder avoids the O(N^2) wall (H2C8 pipeline): - Multi-tier match finding: dual-level hash chains for local matches paired with an O(N) SA-IS suffix array for deep, long-range matches. - Sparse DP parsing: instead of evaluating every edge in the graph, it groups Elias gamma bit costs into mathematical plateaus to skip redundant searches.
The repo ships with three 0-alloc decoder implementations: 1. Portable C (`lz0dec_min.c`): ~75 lines of freestanding C with z […]