Well, the fact is that in the LZ4 bitstream, offsets are hard-coded as 16-bit integers (2-byte uint16_t). It is physically impossible for LZ4 to reference a byte located more than 65,535 bytes back. So, on a 1.3 MB binary (bash_x86_64 for example) or a 5 MB blob, LZ4 is blind to long-range repetitions. On blob_png_5m.bin, LZ0 Ultra beats LZ4HC by 830 KB because LZ0 can reference chunks of duplicated image data located several megabytes apart.
Furthermore, in LZ4, every token costs 1 byte, every offset costs a full 2 bytes, and every length extension costs 1 extra byte. In contrast, in LZ0, the Literal vs Match decision takes a single bit. Reusing the same offset costs only 1 bit plus the Elias-encoded length. Offsets are encoded with Elias gamma + 7 trailing LSB bits, and reusing a recent offset often costs 4 to 8 bits total in LZ0, versus a minimum of 24 bits in LZ4.
Also, LZ4 produces some inflation (expansion under 1%, however) on JPG, PNG, or already-compressed data. LZ0 has virtually zero inflation and does not corrupt the ratio on multimedia files.
That said, let's not forget that LZ4 decompresses faster than LZ0 (byte-aligned format with no bit shifting). But compared with the dense compressors in its category (ZX0, UPKR, ...), LZ0 offers the density of an optimal unbounded-window compressor while approaching LZ4-class throughput (well, within a factor of 2x to 4x, versus lagging ~30x to 100x for ZX0/UPKR).
I've just updated the readme with the exact measured numbers, thanks for pointing it out (this ~200 bytes remark was an outdated note in the readme from a first unrolled loop prototype)
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.
You're right : a minimalist LZ4 decoder can be written in ~150-200 bytes of assembly or even ~35 lines of C because it doesn't have to handle a bitstream. However, LZ0's compact decoders are exactly the same size:
lz0dec_x86_64.s: 184 bytes
lz0dec_arm64.s: 180 bytes (pure leaf, 0 bytes of stack)
lz0dec_riscv64.s: 160 bytes (pure leaf, 0 bytes of stack)
lz0dec_min.c: 47 lines of C, 0 allocations, 0 libc
So LZ0 offers the same decoder compactness as a minimal LZ4 decoder, but for an Elias gamma bitstream with arbitrary window.
README.md in particular mixes English and French, which was confusing at first. I have seen this person from encode.su, where one said one is not fluent in English so uses French as an LLM prompt, so that's probably why.
No offence, as you're absolutely right: originally, I wrote this for my own personal needs, mainly for embedding resources into binaries or for use on highly constrained systems. I was simply looking for an alternative to ZX0, which has a very good ratio, a very simple decoder, and good decompression speed. However, its encoding is extremely slow (far too slow for my use cases). There's also UPKR, which achieves even better ratios and has fast encoding, but its decoder is more complex and, above all, quite slow at decompression. My idea was to try to build something offering the density of an optimal unbounded-window compressor while approaching the throughput of LZ4-class codecs (with a 2x to 4x factor, vs 30x to 100x deficit for ZX0/UPKR). I ended up with a (maybe) interesting compromise, and that's why I decided to post it on GitHub and here, thinking this work might serve as inspiration for other developers...
I'm doing this in my free time, and while I've put a lot of care into my code, I DID use LLMs to format and write the GitHub documentation, especially since all my notes for this project were pretty chaotic... The result is indeed a bit "AI slop", but as I explained, I didn't think it would interest that many people anyway, so apart from a (too) quick proofread, I honestly didn't carefully revise the README in particular. Sorry about that, I'll try to fix it.
Thanks for being forthcoming and honest. I think a hand-written README will really stand out in this day and age, since we get so few of them!
I recently used ZX0 for a project where I wanted a lot of compression on slow hardware (basically using it to page in/out code, as ZX0 can compress most architectures quite well).
>"LZ0 is an experimental lossless compression format and C implementation designed around a single guiding principle:
Move complexity from the decoder to the encoder."
Great idea!
Also, LZ0 might be great for compressing a computer's unused (aka "swap") virtual memory pages, i.e., like ZRAM, because if we think about the usage paradigm for that, the compress phase doesn't need to be time-bound, that is, page compression (if properly implemented) could use simply unused CPU cycles... i.e., not time bound if it doesn't need to be compressed and stored immediately...
Decompression on the other hand (i.e., the page is needed by the computer) is a completely different story! Every nanosecond that a computer has to wait for a requested page costs the program which needs it, TIME! That is, the program (or thread(s) requiring that memory) are typically halted until it becomes available!
So decompression of requested previously unused swapped memory pages must happen as soon as possible, if not sooner! (ideally instantly -- which could be the case or close to the case if the page is sent through dedicated decompression hardware!)
Anyway, LZ0 (if the decompression is fast enough!) might make a great swap memory page compressor/decompressor!
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 zero libc dependencies. 2. Compact ASM: hand-written x86-64 and ARM64 routines (~1.3 KiB of machine code), with zero state or lookup tables. 3. High-throughput "FAST" ASM: dual-engine vector path (SSE2 on x86-64, NEON on ARM64) using branch-free Elias gamma decoding and segment-window refills.
All decoders enforce strict bounds checks and have been validated against 240,000+ guard-page and fuzzing tests to ensure corrupt streams never trigger out-of-bounds reads or crashes.
Shameless, albeit relevant plug for people interested in asymmetric LZ: https://github.com/welcome-to-the-sunny-side/misa77
Be nice to see benchmarks against lz4hc -9, since that's the closest competitor in terms of both compression speed and decompression speed.
Well, the fact is that in the LZ4 bitstream, offsets are hard-coded as 16-bit integers (2-byte uint16_t). It is physically impossible for LZ4 to reference a byte located more than 65,535 bytes back. So, on a 1.3 MB binary (bash_x86_64 for example) or a 5 MB blob, LZ4 is blind to long-range repetitions. On blob_png_5m.bin, LZ0 Ultra beats LZ4HC by 830 KB because LZ0 can reference chunks of duplicated image data located several megabytes apart. Furthermore, in LZ4, every token costs 1 byte, every offset costs a full 2 bytes, and every length extension costs 1 extra byte. In contrast, in LZ0, the Literal vs Match decision takes a single bit. Reusing the same offset costs only 1 bit plus the Elias-encoded length. Offsets are encoded with Elias gamma + 7 trailing LSB bits, and reusing a recent offset often costs 4 to 8 bits total in LZ0, versus a minimum of 24 bits in LZ4. Also, LZ4 produces some inflation (expansion under 1%, however) on JPG, PNG, or already-compressed data. LZ0 has virtually zero inflation and does not corrupt the ratio on multimedia files. That said, let's not forget that LZ4 decompresses faster than LZ0 (byte-aligned format with no bit shifting). But compared with the dense compressors in its category (ZX0, UPKR, ...), LZ0 offers the density of an optimal unbounded-window compressor while approaching LZ4-class throughput (well, within a factor of 2x to 4x, versus lagging ~30x to 100x for ZX0/UPKR).
Thanks for sharing- starred and followed!
Lz0 is now integrated into TurboBench [1], including benchmarks with lz0 compact [2] for memory contrained systems.
[1] https://github.com/powturbo/TurboBench
[2] https://github.com/powturbo/TurboBench/blob/master/turbobenc...
lz0dec_min.c decoder is 894B on RV32IMC. You should fix your README, which states 200 (where did you get this number from?).
I've just updated the readme with the exact measured numbers, thanks for pointing it out (this ~200 bytes remark was an outdated note in the readme from a first unrolled loop prototype)
[flagged]
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.
You're right : a minimalist LZ4 decoder can be written in ~150-200 bytes of assembly or even ~35 lines of C because it doesn't have to handle a bitstream. However, LZ0's compact decoders are exactly the same size: lz0dec_x86_64.s: 184 bytes lz0dec_arm64.s: 180 bytes (pure leaf, 0 bytes of stack) lz0dec_riscv64.s: 160 bytes (pure leaf, 0 bytes of stack) lz0dec_min.c: 47 lines of C, 0 allocations, 0 libc
So LZ0 offers the same decoder compactness as a minimal LZ4 decoder, but for an Elias gamma bitstream with arbitrary window.
Interesting — Although I care more about speed and compression ratio, it seems like Zstd would still beat LZ0.
Still, it could be a good fit for use cases like embedded systems with very limited bandwidth and RAM.
I don't want to be a jerk, but was all the documentation for this just AI-slopped out with zero editing?
README.md in particular mixes English and French, which was confusing at first. I have seen this person from encode.su, where one said one is not fluent in English so uses French as an LLM prompt, so that's probably why.
No offence, as you're absolutely right: originally, I wrote this for my own personal needs, mainly for embedding resources into binaries or for use on highly constrained systems. I was simply looking for an alternative to ZX0, which has a very good ratio, a very simple decoder, and good decompression speed. However, its encoding is extremely slow (far too slow for my use cases). There's also UPKR, which achieves even better ratios and has fast encoding, but its decoder is more complex and, above all, quite slow at decompression. My idea was to try to build something offering the density of an optimal unbounded-window compressor while approaching the throughput of LZ4-class codecs (with a 2x to 4x factor, vs 30x to 100x deficit for ZX0/UPKR). I ended up with a (maybe) interesting compromise, and that's why I decided to post it on GitHub and here, thinking this work might serve as inspiration for other developers... I'm doing this in my free time, and while I've put a lot of care into my code, I DID use LLMs to format and write the GitHub documentation, especially since all my notes for this project were pretty chaotic... The result is indeed a bit "AI slop", but as I explained, I didn't think it would interest that many people anyway, so apart from a (too) quick proofread, I honestly didn't carefully revise the README in particular. Sorry about that, I'll try to fix it.
Thanks for being forthcoming and honest. I think a hand-written README will really stand out in this day and age, since we get so few of them!
I recently used ZX0 for a project where I wanted a lot of compression on slow hardware (basically using it to page in/out code, as ZX0 can compress most architectures quite well).
>"LZ0 is an experimental lossless compression format and C implementation designed around a single guiding principle:
Move complexity from the decoder to the encoder."
Great idea!
Also, LZ0 might be great for compressing a computer's unused (aka "swap") virtual memory pages, i.e., like ZRAM, because if we think about the usage paradigm for that, the compress phase doesn't need to be time-bound, that is, page compression (if properly implemented) could use simply unused CPU cycles... i.e., not time bound if it doesn't need to be compressed and stored immediately...
Decompression on the other hand (i.e., the page is needed by the computer) is a completely different story! Every nanosecond that a computer has to wait for a requested page costs the program which needs it, TIME! That is, the program (or thread(s) requiring that memory) are typically halted until it becomes available!
So decompression of requested previously unused swapped memory pages must happen as soon as possible, if not sooner! (ideally instantly -- which could be the case or close to the case if the page is sent through dedicated decompression hardware!)
Anyway, LZ0 (if the decompression is fast enough!) might make a great swap memory page compressor/decompressor!
[flagged]
[flagged]
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 zero libc dependencies. 2. Compact ASM: hand-written x86-64 and ARM64 routines (~1.3 KiB of machine code), with zero state or lookup tables. 3. High-throughput "FAST" ASM: dual-engine vector path (SSE2 on x86-64, NEON on ARM64) using branch-free Elias gamma decoding and segment-window refills.
All decoders enforce strict bounds checks and have been validated against 240,000+ guard-page and fuzzing tests to ensure corrupt streams never trigger out-of-bounds reads or crashes.
Bitstream specification: https://github.com/seb3773/lz0/blob/main/docs/LZ0_FORMAT.md Benchmarks: https://github.com/seb3773/lz0/blob/main/docs/BENCHMARKS.md
I'd appreciate any feedback on the bitstream layout, the decoder tradeoffs, or edge cases I might have missed.