A lightweight, asymmetric LZ compressor designed around an extremely simple, memory-free decoder.

LZ0 is an experimental lossless compression format and C implementation designed around a single guiding principle:.

Move complexity from the decoder to the encoder.

In a recent development, instead of balancing computational cost equally between compression and decompression, LZ0 deliberately spends more effort during encoding to generate a compact, structured stream that can be decompressed by an ultra-minimal routine. The decoder requires no dynamic memory allocation (malloc), maintains minimal state, and processes explicit LZ tokens at hundreds of megabytes per second. (Related: AI for Game Development: Creating a Farming Game in 5 D...)

LZ0 is primarily targeted at small-to-medium binary blobs and structured datasets, typically ranging from a few hundred kilobytes to several megabytes.

Compression algorithms face an inherent multi-dimensional trade-off between compression ratio, encoding speed, decoding speed, and implementation complexity. (Related: AssetOpsBench: Bridging the Gap Between AI Agent Benchm...)

LZ0 resolves this trade-off strictly from the decoder's perspective:.

LZ0 occupies a distinct design niche between simple retro LZ formats (like ZX0) and modern adaptive entropy-coded LZ compressors (like UPKR).

ZX0 established the gold standard for minimal-decoder LZ compression, pairing a byte-by-byte overlapping copy decoder with an optimal-rate dynamic programming parser. However, ZX0's exhaustive search can take several minutes on inputs larger than 1 MiB.

LZ0 shares ZX0's philosophy of decoder simplicity and Elias-based variable integer coding, but adopts a fundamentally faster encoder architecture (combining a hash chain with an $O(N)$ SA-IS suffix array and a sparse dynamic programming parser) and its own bitstream grammar. This produces comparable ratios in seconds instead of minutes.

UPKR achieves high compression ratios by coupling LZ matching with adaptive entropy coding (rANS / rABS). This requires the decoder to maintain probability distributions and perform entropy-state updates on every token.

Industry observers note that LZ0 deliberately eschews adaptive entropy coding. Its decoder processes raw bits and Elias gamma integers, trading a fraction of compression ratio for dramatic simplicity and higher decoding throughput.

The LZ0 decoder interprets a sequence of four semantic operations:.

The decoder maintains minimal state:.

In a recent development, matches are copied byte-by-byte (out[out_pos + i] = out[src + i]). Because src = out_pos - offset, when length > offset the copy automatically repeats earlier bytes. For example, an offset of 1 with a length of 8 expands a single byte into an 8-byte run. Standard non-overlapping memcpy must not be used.

LZ0 differentiates between the raw compressed bitstream and the on-disk container format.

Files stored on disk or handled by the lz0 CLI wrap the raw payload in a minimal 8-byte header:.

Sources indicate that the raw bitstream has no magic bytes, header, or length metadata. It is normative according to docs/LZ0_FORMAT.md.

Used for variable-length integers ($v \ge 1$):.

Recent findings suggest that valid offsets satisfy $1 \le \text{offset} \le \text{out_pos}$. Offsets are split into an MSB and an 8-bit remainder: $$\text{msb} = \lfloor (\text{offset} - 1) / 256 \rfloor + 1 = ((\text{offset} - 1) \gg 8) + 1$$ $$\text{rem} = (\text{offset} - 1) \ & \ 255$$.

Matches with a new offset require $L \ge 2$. Let $v = L - 1$:.

Sources indicate that the production encoder configuration is H2C8 (Hash 3 + Chain 8 + SA-IS + Sparse DP $K=2$). It processes data through three distinct stages:.

Instead of a greedy heuristic or a memory-intensive full DP lattice, LZ0 maintains Pareto-optimal live states per input position ($K=2$ in default -6, and adaptive $K=32/16/8$ in Ultra -9 according to file size).

The repository provides independent, interoperable decoders tailored for different footprint and throughput requirements:.

Les décodeurs assembleur introduisent plusieurs innovations micro-architecturales avancées :.

Architecture à deux moteurs (FAST vs SAFE) :.

La "Fenêtre de Segment" et Décodage In-Window Étendu ($n \le 15$) :.

Décodage Elias Gamma sans branchement (Branch-Free) :.

Lecteur de bits à sentinelle (Décodeurs Compacts) :.

All decoders adhere to strict safety guarantees:.

Industry observers note that measured on x86_64 Linux (GCC -O3). Reproducible via make bench_all and make bench_dec. All LZ0 decompressions verified 100% bit-exact against uncompressed originals.

Comparison on real-world representative files (Canterbury, Silesia, Windows PE, ELF, pre-compressed images/audio, and raw media textures) between LZ0 (default -6 and ultra -9), UPKR, LZ4, and ZX0:.

In a recent development, key takeaway: LZ0 delivers dense ratios competitive with UPKR on text and binaries while systematically outperforming both UPKR and LZ4 on pre-compressed and high-entropy media (avatar.jpg and break.mp3 with zero inflation). Against LZ4, LZ0 cuts compressed size by 15% to 48%, while providing decompressor throughputs of 400 to 1,355 Mo/s (up to 10,000+ Mo/s on images).

In embedded scenarios (firmware, game resource packages, packers), multiple disparate files are concatenated into a single continuous binary blob. Under Approach A, the compressed data remains one single continuous LZ0 stream decompressed by freestanding routines (<300 bytes) without container metadata:.

Measured with make bench_dec (x86-64 native) and make bench_dec_arm64 (AArch64 under QEMU):.

Key Architectural Takeaways on Decompression Speedup:.

Measured on in-memory PRNG-generated datasets (docs/BENCHMARKS.md):.

A standard C11 compiler (gcc or clang) and make are required:.

The lz0 executable operates on disk files using the LZ01 container:.

In a recent development, the decompression API does not allocate memory. The caller supplies the destination buffer:.

This project is licensed under the same terms as the repository root (LICENSE).

LZ0 builds upon concepts from the LZ77/LZSS compression lineage and takes major inspiration from ZX0 by Einar Saukas, particularly in its commitment to decoder simplicity and Elias-coded offset hierarchies.

→ Read original article