r/Clickhouse • u/soyayaos • 19h ago
Got nerd-sniped by the 26.11 release call and rewrote ClickHouse's PCO codec (pcodec) in Zig (~1.9-2.2x faster MergeTree writes/merges)
Hey everyone,
I was watching the ClickHouse 26.11 release call and caught Alexey Milovidov casually mentioning pcodec (the PCO numerical codec). Got curious how it ticks under the hood and fell down a rabbit hole trying to see if I could squeeze more speed out of it.
The result is pcodec.zig — a standalone Zig rewrite that keeps the exact same wire format so existing data doesn't break, whether used via CLI/C library or plugged straight into ClickHouse's PCO codec.
Compatibility first (so nobody has to worry about bricking existing parts): two-way wire compatibility with Rust pco 1.1.0 passes 323 differential checks, all 8 wrapper unit tests, and ClickHouse SQL tests — tables written by either side read back fine on the other.
Here are the headline numbers against Rust pco 1.1.0:
| Workload | Before (Rust pco 1.1.0) | After (pcodec.zig) | Gain |
|---|---|---|---|
| x86-64 compression (1 core, 20 datasets) | 1.00x | 2.15x (1.32-4.46x) | +115% |
| x86-64 decompression (1 core, 20 datasets) | 1.00x | 1.91x (1.24-2.40x) | +91% |
| AArch64 compress / decompress (1 core) | 1.00x / 1.00x | 1.87x / 1.93x | +87% / +93% |
| ClickHouse MergeTree write / merge (20M rows) | 1.00x / 1.00x | 1.88x / 2.16x | +88% / +116% |
| ClickHouse MergeTree read (1 / 8 threads) | 1.00x / 1.00x | 1.46x / 1.33x | +46% / +33% |
| Compressed payload size (no index, geomean) | Baseline | -0.53% (up to -7.7%) | Smaller |
Full benchmark methodology and dataset breakdowns are in the repo. If anyone runs numeric-heavy MergeTree tables and wants to kick the tires on real data (or poke holes in the benchmarks), I'd genuinely love to hear how it behaves on your workload.
- Repo: https://github.com/speed-this-ship-up/pcodec.zig
- Full benchmarks: https://github.com/speed-this-ship-up/pcodec.zig/blob/main/docs/benchmarks.md
- Original Rust pcodec: https://github.com/pcodec/pcodec