lzcsv 1.0: Turn Your CSV Sideways and Beat xz by 14%
Transpose a CSV column-wise before xz and it compresses 13.9% smaller. lzcsv 1.0 turns the hot_qwen Cycle 1 test into a real command.
lzcsv 1.0 is a standalone CSV compressor that beats xz -6 by 13.9% — not with a better compressor, but by handing xz better input. It transposes the CSV column-wise first, so same-field values become adjacent long runs, and then compresses with plain xz. The trick is old. The measurement is new. And the measurement holds up on files the tool never saw during development.
It lives in the lzply repo, it links only liblzma, and it has nothing to do with the lzply FEC core: no liblzply.a, no CUDA, no parity. Just a transpose and xz.
The idea, and the attempt to kill it
This started in hot_qwen Cycle 1 (December 2026), when the coordinator proposed grid-aware compression for CSVs. hot_qwen — the local Qwen4-35B-A3B running on hot_house — was asked to disprove it. It tried: the prior art is real and old (columnar storage, C-Store and MonetDB, Buchsbaum et al. 2002, Meta's OpenZL), and the failure modes were obvious in advance — short or narrow CSVs, and the loss of row context when you shred rows into columns.
It called the idea testable anyway. The test, on 14 corpus CSVs, gave −13.9% against xz -6. lzcsv is that test turned into a real command.
How it works
A CSV is the worst possible layout for a compressor: every row alternates fields — a date, a country, a number, a string — so the same kind of value is always one row away from the last one. lzcsv transposes the file column-wise into the COLT1 format (byte-compatible with the Cycle 1 Python prototype), so all the dates sit together, all the countries sit together, and all the numbers sit together. Then it runs xz over that.
The transposed stream's compressed bytes are the same liblzma preset-6 stream xz -6 produces — within a few bytes, because the encoder's output varies slightly with how it is fed (1,500 vs 1,504 bytes on tips.csv). Same algorithm, same preset, not a different compressor. The win comes entirely from the layout.
The container is 26 bytes of header — magic LZCSV001, original size, transposed size, preset, flags — followed by the xz stream (liblzma, CRC64 check). Integrity is a chain: liblzma verifies the CRC64, the COLT1 decoder is strict (magic, counts, column field counts, no trailing data), and the header's original size must match the reconstructed output exactly.
The numbers: 14 corpus CSVs
14 CSVs, 12,096,190 bytes, measured on hot_house with xz/liblzma 5.8.1. lzcsv −6 wins on 13 of 14 files against xz -6 and against xz -9e alike — no file flips at any preset.
| file | original | xz −6 | xz −9e | lzcsv −6 | lzcsv −9e | lzcsv −6 vs xz −6 |
|---|---|---|---|---|---|---|
| covid-countries.csv | 5,512,931 | 646,112 | 654,748 | 464,786 | 464,446 | −28.1% |
| gen-log.csv | 373,147 | 38,060 | 38,100 | 29,346 | 29,626 | −22.9% |
| gen-numeric.csv | 971,501 | 171,016 | 171,256 | 136,142 | 137,990 | −20.4% |
| hydra-passwords.csv | 515,376 | 79,832 | 79,816 | 70,434 | 70,050 | −11.8% |
| gapminder.csv | 82,079 | 24,352 | 24,472 | 21,506 | 21,694 | −11.7% |
| diabetes.csv | 23,873 | 8,076 | 8,080 | 7,422 | 7,446 | −8.1% |
| default-passwords.csv | 90,856 | 25,900 | 25,892 | 23,898 | 23,906 | −7.7% |
| tips.csv | 7,943 | 1,636 | 1,640 | 1,526 | 1,502 | −6.7% |
| mam.csv | 608,108 | 192,364 | 192,496 | 179,690 | 179,906 | −6.6% |
| iab.csv | 381,908 | 128,396 | 128,392 | 120,114 | 120,342 | −6.5% |
| stocks.csv | 67,924 | 24,092 | 24,132 | 22,698 | 22,718 | −5.8% |
| oui.csv | 3,372,302 | 718,664 | 713,760 | 692,506 | 687,758 | −3.6% |
| iris.csv | 4,601 | 824 | 828 | 818 | 818 | −0.7% |
| pin-codes.csv | 83,641 | 12,864 | 12,844 | 13,994 | 14,066 | +8.8% |
| aggregate (ratio) | 12,096,190 | 2,072,188 (0.1713) | 2,076,456 (0.1717) | 1,784,880 (0.1476) | 1,782,268 (0.1473) | −13.9% |
Aggregate: lzcsv −6 beats xz -6 by 13.9% (2,072,188 → 1,784,880 bytes) and beats xz -9e by 14.0%. The extreme preset buys almost nothing on top: lzcsv −9e is only 0.15% smaller than lzcsv −6. Preset 6 is the sweet spot.
xz's best does not erase the win
This is the check that matters, and it is stated plainly: reaching for xz's strongest setting does not close the gap. Direct xz -9e is slightly worse than xz -6 on these CSVs (2,076,456 vs 2,072,188 bytes), and xz -9 is byte-identical to xz -6 on all 14 files. The transpose is doing work no preset can do, because the preset was never the bottleneck — the row-major layout was.
Held out: 18 files it never saw
A corpus win is only interesting if it survives contact with new files. The held-out set is 18 CSVs totalling 4,431,565 bytes — 5 downloaded real-world files plus 13 generated edge cases:
| aggregate | xz −6 | xz −9e | lzcsv −6 | lzcsv −9e | lzcsv −6 vs xz −6 |
|---|---|---|---|---|---|
| 18 held-out CSVs (ratio) | 844,752 (0.1906) | 842,764 (0.1902) | 730,756 (0.1649) | 726,864 (0.1640) | −13.5% |
lzcsv −6 wins 9 of 18 held-out files, and the aggregate win is −13.5% — essentially the same as the corpus result. Best held-out wins: flights −21.9%, text −21.4%, diamonds −18.9%, taxis −13.3%. The win is not a corpus artefact.
The losses, stated honestly
Two files in the corpus table deserve attention. pin-codes is the only corpus loss: +8.8% (13,994 vs 12,864 bytes). Short, near-random numeric codes gain nothing from being grouped — the transpose just adds headers.
All 9 held-out losses follow the same pattern: files under ~1 KB, or single-column files. The fixed overhead — the COLT1 header plus per-column headers plus the 26-byte LZCSV header plus the xz stream itself — dominates on tiny files (empty.csv: 0 bytes → 98; tiny.csv: 24 bytes → 134). Single-column files gain nothing from transposition, because there is only one column to transpose into — xz −9e beats lzcsv there (single-col.csv: 1,152 vs 1,474 bytes). A size gate — transpose only above a row/column threshold, pass small files through as plain xz — is the obvious next step, and it is left for a later cycle.
Scope, stated plainly: CSVs are about 0.6% of the full 48 MB corpus this work draws from. This is a real win on one category, not a breakthrough. It does not make lzcsv a general compressor, and it should not be sold as one.
Speed and correctness
Encode times are roughly comparable to xz: on the corpus, xz −6 took 3.59 s against lzcsv −6's 4.08 s (sums of per-file medians, approximate); on the held-out set, 3.30 s against 2.00 s. Decode is at parity. The transpose itself is negligible next to xz.
Round-trips are byte-exact on all 32 files (14 corpus + 18 held-out). COLT1 output is byte-identical to the Cycle 1 Python prototype. Malformed input is rejected cleanly — embedded newlines and mixed line endings both fail with an error instead of silently producing a wrong file.
Get it
lzcsv 1.0 is in the lzply repo at commit e8f61d7 on main. Build it with make lzcsv (needs liblzma-dev; the target is skipped cleanly without it). It is C, and it links only liblzma.
make lzcsv
lzcsv c in.csv out.lzcsv # compress (preset 6)
lzcsv c -e in.csv out.lzcsv # extreme preset (-9e)
lzcsv d in.lzcsv out.csv # decompress
lzcsv test in.csv # in-memory round-trip check
lzcsv selftest # built-in synthetic tests
There is also lzcsv info (show the container header) and lzcsv raw-enc / raw-dec for writing and reading the COLT1 intermediate directly — useful if you want to inspect what the transpose actually does to your data before xz ever sees it.
Source: github.com/cnmcdee/lzply. If your CSVs live above a few KB and have more than one column, this is a free 14% — the same xz, fed properly.