nattviken

18 November 2026

hZ vs the established tools: smaller and faster on six corpora of nine

Update: since 2026-11-20 it is seven of nine. The current table is on the project page.

The report in the repo compared size and time separately. That is the easy question. The hard one is whether hZ beats the same opponent on both axes at once: a smaller archive and a shorter packing time than the best established tool on that particular corpus, measured on the same machine.

So the opponent is not chosen by me. For each corpus it is whichever of gzip, bzip2, zstd and xz produced the smallest archive, with its own measured packing time. Of hZ's modes, the smallest one that dominates is counted.

The outcome

corpusbest establishedhZoutcome
source codexz -9e 8,629,516 B / 47 snormal 8,580,323 B / 40 s−0.57 % and 15 % faster
PNG imageszstd -22 257,132,369 B / 156 snormal 230,452,176 B / 127 s−10.4 % and 18 % faster
JPEG photosbzip2 -9 424,611,032 B / 57 snormal 361,834,581 B / 48 s−14.8 % and 16 % faster
archives of archiveszstd -22 254,567,277 B / 154 snormal 254,287,214 B / 153 s−0.11 % and 1 % faster
log filesxz -9e 12,419,456 B / 897 ssmall 10,512,452 B / 191 s−15.4 % and 79 % faster
Silesiaxz -9e 48,408,228 B / 158 ssmall 45,657,473 B / 100 s−5.7 % and 37 % faster
GIF imageszstd -22 14,867,185 B / 5 ssmall 14,864,575 B / 6 s−0.02 %, but 20 % slower
filmzstd -19 557,861,782 B / 57 snormal 557,880,433 B / 56 sfaster, but 18 kB larger
enwik8xz -9e 24,831,492 B / 121 ssmall 21,417,335 B / 129 s−13.8 %, but 7 % slower

Six of nine, and the three that remain are the three where there is nothing to win. GIF and film are already entropy-coded — 0.02 and 0.00 percent to gain respectively — so all that shows is hZ's fixed cost. enwik8 is a single file, and that is worse than it sounds: hZ cannot even split the work, because a block is filled with whole objects and a 95 MB file therefore always ends up in one block. Dedup, sorting and transforms have nothing to contribute, and what remains is hzcm's price in time.

So the line does not run between data types. It runs between exploitable structure and none.

Four measurements that moved something

The dictionary must cover the block. LZMA's preset 9e has a fixed 64 MiB dictionary. hZ's blocks are larger — 192 MiB for ordinary classes, the whole corpus for opaque ones — so by construction the compressor could not see a repetition further back than 64 MiB, however large the block was. And that is exactly the repetition that dedup and sorting put there. Measured on 120 MiB of archive data: 98,700,988 bytes with a 64 MiB dictionary, 96,559,784 with one covering the input. 2.17 % smaller and 12 % faster — a match found is cheaper than a search continued.

The sample has a blind spot. The codec probe takes 4 MiB as eight detached pieces of the block. The right design for seeing what the data is, but it tears apart the long-range structure that separates the codecs: eight pieces from different parts of the block share no repetitions. On a 120 MiB block from the archive corpus the probe chose zstd and got 100.13 MiB, while xz with a covering dictionary gave 91.97. The probe missed eight percent.

The registry carried 16 bytes of hash per file. The hash exists so that hz -t can detect mis-mounted content, and 32 bits are enough for that — bit errors are already caught by the blocks' CRC64. But hashes are random and therefore incompressible: on the code corpus they were 94,368 bytes of a 239,049-byte registry. Eleven per mille of the whole archive, in a field nobody reads.

The cheap step was not cheap. The two-step rule for opaque blocks used zstd -19 to answer the question "does this block have tens of percent to give?". That question needs no strong compressor. zstd -3 --long=27 gives the same answer in 725 milliseconds instead of 48 seconds.

Three of the changes fixed regressions they had caused themselves

This is the part I take with me. The covering dictionary tied up 2.7 GB per encoder, and since the memory gate then let only one through at a time, the PNG corpus went from 268 to 841 seconds — for a 0.06 % smaller archive. A dictionary win that removes the parallelism is no win. The fix was embarrassingly simple in hindsight: a dictionary larger than the block cannot be used by construction, but it costs memory anyway. The floor was removed and the time became 127 s.

The same pattern twice more. Always re-testing the codec choice on the whole block doubled enwik8 from 131 to 259 seconds without saving a single byte — on text hzcm wins by tens of percent and wins the whole block too, so the re-test is now only done when the probe's lead was thin. And zstd -3 without a long window saw only 2.6 % of the archive corpus's 33: the whole escalation was skipped and the archive grew from 248 to 271 MB, until --long=27 gave 27.6 % in the same 725 ms. The window was free; the level was expensive.

And a bug that was not in hZ

In the middle of re-measuring, two rows reported that three files did not come back identical. The archive was flawless. It was the corpus that moved: bygg-korpus.py hard-links instead of copying, so the file in korpus/kod is the same inode as the file in the live working tree — 5,971 of 5,974 files in the code corpus, and all of them in png, photo, gif and film. Three files in a project tree were saved in another window while the measurement was running.

The log corpus has always been copied for exactly that reason; it said so in the build script's own header. The conclusion applied to all corpora. The measurement script now fingerprints the corpus before and after every run and refuses to interpret a run where it moved, and the corpus can be frozen with --kopiera. But the consequence is broader than two rows: every number measured before this day rests on a corpus that could move.

What could not be won

Three things remain, and they belong in a report as much as the wins. GPU mode still wins no block — LZ77 matching is 2.5× faster on the graphics card, but entropy coding is serial and Amdahl wins. Below 30 kB of input hZ is larger than xz -9e, and the whole loss is the registry: the payload is already 80 bytes smaller than xz's entire file. And hzjpg sits five percentage points below packJPG and Lepton, which have done the same thing since 2006 and 2016 respectively — which is also the answer to everyone who asked whether anything here is new. No single method is. The packaging and the measurement are.

The full material: eleven corpora, 1,000 randomized trees, the Linux kernel fetched from kernel.org with md5 before and after, plus zlib-ng's corpora — in the full report.

← All field notes