Skip to content

Add experimental Wallaby floating-point compression codec - #113575

Open
alexey-milovidov wants to merge 155 commits into
masterfrom
wallaby-codec
Open

alexey-milovidov wants to merge 155 commits into
masterfrom
wallaby-codec

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Related: #66467
Related: #110613

Wallaby

Wallaby is an experimental lossless codec for Float32 and Float64 columns, enabled by enable_wallaby_codec.

Motivation. The previous revision of this pull request bit-packed its integers and fell back to XOR, and PCO (the pcodec crate, #110613) produced smaller data on 9 of 11 real columns. A new floating-point codec only makes sense if it is better than what is already there, so the codec is rewritten around an entropy coder with one goal: to be smaller than both ALP and PCO on every column, at a speed comparable to PCO.

How it works. A block is split into chunks of up to 16384 values; every chunk is coded independently, with the method chosen by measuring.

  1. Integerization. The front-end is one of: the bit patterns in the numeric order with the common trailing zeros removed; division by a denominator (decimals, and other rational grids such as averages of decimals over 60 samples — the denominator is found by continued fractions and by trying small multiples of powers of ten); multiplication by a constant (values that were produced by one and are not correctly rounded decimals). Float32 values can be reconstructed in single precision. Values that are slightly off the grid get adjustments (a distance in the order of bit patterns); values with no integer (NaN, infinities) or the few values that are off the grid become exceptions, which are removed from the sequence and coded separately.
  2. Prediction. A common divisor and a base are removed, then differences of order 0 to 7 with an optional center.
  3. Entropy coding. tANS with 4 interleaved states. The alphabet is fitted to the chunk: dictionary symbols for frequent exact values are mixed with logarithmic or fixed-width bins whose low bits are stored raw, zero runs are symbols of their own, and the frequencies can depend on the magnitude of an earlier token (up to 3 contexts). The model is described by a few parameters, so the header stays small on the 8192 or 16384 values that a MergeTree compressed block holds. This is the regime that matters here: compressing every 64 KiB block on its own costs PCO 20-45% of the ratio it has on a whole column (measured for the previous revision of this description).

The encoder ranks the candidates (front-end and differencing order) by a cheap proxy. For the best few it counts the exact values of the stream — in an array indexed by the value when the range is narrow, in a hash table when a sample has repeated values — and the bins, the dictionary and the size (within about 1%) follow from the distinct values without further passes over the data; the full work is done only for the winner. Float32 is processed in 32-bit integers throughout: the arithmetic on its latents is modulo 2^32. The decoder is a fused loop over tokens and raw bits, in batches, with the exceptions placed directly.

The implementation is src/Compression/Wallaby.cpp (the format is described at its top); CompressionCodecWallaby.cpp is the codec glue. Nothing is shared with the previous revision, whose format-specific tests are replaced.

Results. Measured inside ClickHouse with one binary for all the codecs (clickhouse local, MergeTree wide parts, max_threads = 1, sparse serialization off so that every codec sees every value; PCO at its default level). Real columns are taken in full from the sample datasets: ClickBench hits (numeric columns cast to floats, 100M rows), mgbench machine metrics (22M rows), environmental sensors (2019-06, 31M rows), NOAA weather (100M rows), cell towers (43M rows) and New York taxi trips (3M rows). The numbers are for this dataset and machine, not a general claim.

  • Size: Wallaby is smaller than ALP on 49 of 49 real columns and smaller than PCO on 49 of 49. In total the 49 columns take 2032.1 MB with ZSTD(3), 3303.9 MB with ALP, 1704.5 MB with PCO and 1365.6 MB with Wallaby: 19.9% less than PCO and 58.7% less than ALP. Per column against PCO: from -55.3% to -0.5%, median -24.0%.
  • Synthetic series (24, 4.2M values each): smaller than ALP on 24 and than PCO on 23; in total 439.3 MB (ALP), 251.4 MB (PCO), 231.2 MB (Wallaby).
  • Not smaller: synthetic rnd (Float64) vs PCO: +0.01% (uniformly random doubles, a few bytes per block).
  • Scan (SELECT of the whole column): 7.51 s with PCO and 7.02 s with Wallaby over the real columns (3.94 s with ALP, 6.09 s with CODEC(NONE)). Wallaby is not slower than PCO on 32 of 49 columns; per column it takes from 0.59x to 1.46x of the time of PCO.
  • Insert (the whole INSERT, of which 12.1 s is the pipeline that CODEC(NONE) also pays): 60.7 s with PCO and 51.1 s with Wallaby (26.4 s with ALP). On the 12 Float64 columns Wallaby is faster than PCO in total (16.4 s against 22.0 s), and on the 37 Float32 columns it is faster than PCO (34.8 s against 38.7 s). Per column it takes from 0.44x to 1.27x of the time of PCO, and is not slower on 33 of 49.
  • ALP remains much faster than both entropy coders (1.9x faster to insert and 1.8x faster to scan than Wallaby in total): it is bit-packing. Wallaby is for the columns where the size matters most.
  • Against the slowest level, PCO(12), measured on a sample of 512 blocks of every column: Wallaby is smaller on 70 of 71 columns; the exception is the synthetic column of uniformly random doubles (+0.04%).

Compressed size of the column, the smallest of the three floating-point codecs in bold:

Column ZSTD(3) ALP PCO Wallaby vs ALP vs PCO
cell towers lat (Float64) 221.1 MB 207.5 MB 189.1 MB 174.1 MB -16.1% -7.9%
cell towers lon (Float64) 225.6 MB 213.1 MB 200.9 MB 181.4 MB -14.9% -9.7%
cell towers range (Float64) 35.1 MB 81.4 MB 24.6 MB 22.1 MB -72.9% -10.4%
hits EventTime (Float64) 235.6 MB 215.9 MB 128.1 MB 126.0 MB -41.6% -1.6%
hits RegionID (Float32) 52.0 MB 202.7 MB 53.9 MB 38.5 MB -81.0% -28.5%
hits ResolutionWidth (Float32) 37.9 MB 141.7 MB 43.1 MB 26.3 MB -81.4% -39.0%
hits SendTiming (Float32) 20.4 MB 64.0 MB 11.5 MB 11.1 MB -82.7% -3.6%
hits UserID (Float64) 149.7 MB 684.2 MB 120.3 MB 119.4 MB -82.5% -0.8%
mgbench bytes_in (Float32) 58.9 MB 75.5 MB 48.8 MB 48.3 MB -36.0% -1.1%
mgbench bytes_out (Float32) 56.8 MB 79.1 MB 51.0 MB 48.4 MB -38.8% -5.1%
mgbench cpu_idle (Float32) 33.9 MB 60.8 MB 32.0 MB 22.7 MB -62.6% -28.9%
mgbench cpu_nice (Float32) 5.2 MB 8.3 MB 5.3 MB 3.0 MB -63.4% -43.4%
mgbench cpu_system (Float32) 30.4 MB 55.7 MB 30.2 MB 17.1 MB -69.3% -43.3%
mgbench cpu_user (Float32) 32.0 MB 56.9 MB 31.8 MB 18.7 MB -67.1% -41.2%
mgbench cpu_wio (Float32) 28.9 MB 56.2 MB 28.9 MB 16.0 MB -71.5% -44.6%
mgbench disk_free (Float32) 3.8 MB 11.7 MB 2.4 MB 2.0 MB -82.8% -14.7%
mgbench disk_total (Float32) 67.1 KB 1.3 MB 81.8 KB 54.5 KB -95.8% -33.3%
mgbench load_fifteen (Float32) 27.6 MB 46.2 MB 27.4 MB 15.8 MB -65.8% -42.3%
mgbench load_five (Float32) 42.0 MB 66.7 MB 42.9 MB 24.8 MB -62.8% -42.2%
mgbench load_one (Float32) 44.5 MB 66.8 MB 44.8 MB 26.5 MB -60.4% -40.9%
mgbench mem_buffers (Float32) 27.7 MB 46.2 MB 15.5 MB 13.8 MB -70.2% -11.3%
mgbench mem_cached (Float32) 22.9 MB 49.5 MB 12.7 MB 11.7 MB -76.3% -7.6%
mgbench mem_free (Float32) 48.4 MB 60.5 MB 31.7 MB 31.0 MB -48.8% -2.3%
mgbench mem_shared (Float32) 60.5 KB 318.6 KB 69.9 KB 41.7 KB -86.9% -40.4%
mgbench part_max_used (Float32) 225.7 KB 1.6 MB 399.3 KB 178.6 KB -88.6% -55.3%
mgbench swap_free (Float32) 3.0 MB 12.8 MB 1.9 MB 1.4 MB -88.9% -24.0%
weather averageWindSpeed (Float32) 274.7 KB 1.4 MB 317.4 KB 189.2 KB -86.9% -40.4%
weather elevation (Float32) 393.3 KB 20.5 MB 608.9 KB 398.5 KB -98.1% -34.6%
weather maxWindSpeed (Float32) 274.7 KB 1.4 MB 317.4 KB 189.2 KB -86.9% -40.4%
weather precipitation (Float32) 57.1 MB 132.2 MB 33.7 MB 28.4 MB -78.5% -15.8%
weather snowDepth (Float32) 2.7 MB 13.0 MB 2.8 MB 1.4 MB -89.1% -50.0%
weather snowfall (Float32) 4.0 MB 15.1 MB 2.6 MB 1.9 MB -87.5% -28.2%
weather tempAvg (Float32) 1.9 MB 2.6 MB 1.3 MB 996.3 KB -61.3% -23.9%
weather tempMax (Float32) 36.4 MB 39.4 MB 29.4 MB 22.0 MB -44.0% -25.1%
weather tempMin (Float32) 36.8 MB 39.5 MB 29.2 MB 22.3 MB -43.6% -23.7%
sensors humidity (Float32) 80.2 MB 55.7 MB 82.8 MB 46.7 MB -16.2% -43.6%
sensors lat (Float32) 66.3 MB 83.5 MB 74.8 MB 42.4 MB -49.2% -43.3%
sensors lon (Float32) 72.3 MB 87.5 MB 85.7 MB 44.5 MB -49.2% -48.1%
sensors pressure (Float32) 99.1 MB 98.1 MB 79.7 MB 77.7 MB -20.7% -2.5%
sensors temperature (Float32) 74.4 MB 59.6 MB 64.9 MB 43.0 MB -27.8% -33.6%
taxi distance (Float32) 6.2 MB 4.6 MB 3.8 MB 3.3 MB -27.5% -11.9%
taxi distance (Float64) 6.4 MB 5.6 MB 3.9 MB 3.5 MB -38.3% -10.3%
taxi dropoff_lon (Float64) 8.0 MB 19.9 MB 5.2 MB 5.1 MB -74.3% -0.6%
taxi fare (Float64) 3.7 MB 4.0 MB 2.4 MB 2.2 MB -45.8% -9.4%
taxi pickup_lat (Float64) 8.4 MB 18.4 MB 5.5 MB 5.5 MB -70.1% -0.5%
taxi pickup_lon (Float64) 7.9 MB 19.9 MB 5.1 MB 5.1 MB -74.7% -0.8%
taxi tip (Float64) 4.4 MB 4.4 MB 2.4 MB 2.1 MB -53.1% -13.9%
taxi total (Float32) 5.3 MB 5.4 MB 4.4 MB 3.1 MB -41.8% -29.7%
taxi total (Float64) 6.1 MB 5.4 MB 4.2 MB 3.2 MB -40.0% -22.4%
Column ZSTD(3) ALP PCO Wallaby vs ALP vs PCO
synthetic cumsum (Float64) 9.1 MB 27.2 MB 5.0 MB 2.5 MB -90.9% -50.9%
synthetic f32in64 (Float64) 14.6 MB 27.3 MB 10.6 MB 10.5 MB -61.4% -0.5%
synthetic fahrenheit (Float64) 6.1 MB 15.8 MB 4.1 MB 3.8 MB -75.7% -6.4%
synthetic gauss (Float64) 9.8 MB 6.0 MB 6.0 MB 5.4 MB -8.9% -9.7%
synthetic mixed2dp (Float64) 18.7 MB 17.1 MB 12.5 MB 12.1 MB -29.2% -2.8%
synthetic mon (Float64) 29.2 MB 27.1 MB 17.2 MB 16.5 MB -39.3% -4.3%
synthetic ms (Float64) 8.1 MB 10.6 MB 1.7 MB 1.6 MB -84.8% -3.2%
synthetic mul001 (Float32) 24.8 MB 28.9 MB 15.2 MB 14.0 MB -51.6% -7.9%
synthetic mul01 (Float64) 14.4 MB 9.0 MB 8.8 MB 8.8 MB -2.5% -0.1%
synthetic prices2dp (Float64) 18.2 MB 12.7 MB 12.6 MB 12.2 MB -3.3% -2.6%
synthetic randbits (Float64) 33.6 MB 33.6 MB 33.6 MB 33.6 MB -0.0% -0.0%
synthetic randwalk3dp (Float64) 13.1 MB 8.4 MB 6.1 MB 5.8 MB -31.1% -5.3%
synthetic repeats (Float64) 27.7 KB 109.1 KB 29.8 KB 18.8 KB -82.8% -36.9%
synthetic rnd (Float64) 31.9 MB 31.3 MB 28.9 MB 28.9 MB -7.7% +0.0%
synthetic rtn (Float64) 12.4 MB 9.4 MB 15.6 MB 5.4 MB -42.8% -65.4%
synthetic seq (Float64) 29.3 MB 29.4 MB 474.9 KB 394.5 KB -98.7% -16.9%
synthetic sine2dp (Float32) 24.2 MB 14.0 MB 12.7 MB 11.3 MB -19.6% -11.2%
synthetic sine2dp (Float64) 12.6 MB 7.0 MB 6.1 MB 5.6 MB -19.4% -7.1%
synthetic sinexp (Float64) 32.4 MB 30.8 MB 30.0 MB 29.7 MB -3.4% -1.0%
synthetic smooth (Float32) 27.8 MB 23.3 MB 2.9 MB 2.6 MB -89.1% -11.5%
synthetic smooth (Float64) 30.7 MB 26.9 MB 5.5 MB 5.5 MB -79.7% -1.4%
synthetic sparse (Float64) 678.0 KB 1.8 MB 337.4 KB 280.4 KB -84.1% -16.9%
synthetic special (Float64) 15.3 MB 10.9 MB 8.9 MB 8.6 MB -21.3% -3.4%
synthetic thirds (Float64) 10.8 MB 30.8 MB 6.6 MB 6.1 MB -80.2% -8.1%
Insert / select time of every column, seconds

The best of 2 inserts and of 3 scans, single thread; CODEC(NONE) is the floor of the pipeline. The machine was shared with other jobs during the measurement, so differences of a few percent are noise.

Column NONE ZSTD(3) ALP PCO Wallaby
cell towers lat (Float64) 0.40 / 0.199 1.75 / 0.495 1.36 / 0.164 4.18 / 0.363 3.38 / 0.343
cell towers lon (Float64) 0.39 / 0.191 1.77 / 0.493 1.37 / 0.159 4.18 / 0.358 3.41 / 0.356
cell towers range (Float64) 0.39 / 0.186 0.74 / 0.231 1.06 / 0.090 1.57 / 0.244 1.38 / 0.166
hits EventTime (Float64) 0.84 / 0.425 3.25 / 1.101 2.67 / 0.224 7.24 / 0.539 4.01 / 0.452
hits RegionID (Float32) 0.54 / 0.233 1.11 / 0.289 0.98 / 0.206 2.83 / 0.464 2.52 / 0.430
hits ResolutionWidth (Float32) 0.55 / 0.246 0.97 / 0.282 0.96 / 0.159 2.17 / 0.354 2.40 / 0.476
hits SendTiming (Float32) 0.50 / 0.244 0.63 / 0.178 0.90 / 0.134 1.30 / 0.219 1.14 / 0.186
hits UserID (Float64) 0.85 / 0.419 1.57 / 0.408 2.30 / 0.478 3.40 / 0.482 3.11 / 0.457
mgbench bytes_in (Float32) 0.13 / 0.062 0.32 / 0.123 0.27 / 0.068 1.01 / 0.104 1.15 / 0.123
mgbench bytes_out (Float32) 0.13 / 0.061 0.35 / 0.126 0.29 / 0.068 1.38 / 0.110 1.28 / 0.161
mgbench cpu_idle (Float32) 0.16 / 0.071 0.48 / 0.105 0.30 / 0.065 0.79 / 0.089 1.00 / 0.116
mgbench cpu_nice (Float32) 0.11 / 0.060 0.11 / 0.028 0.19 / 0.025 0.29 / 0.054 0.29 / 0.039
mgbench cpu_system (Float32) 0.13 / 0.063 0.36 / 0.096 0.32 / 0.061 0.77 / 0.100 0.83 / 0.109
mgbench cpu_user (Float32) 0.14 / 0.061 0.37 / 0.098 0.35 / 0.057 0.77 / 0.098 0.87 / 0.110
mgbench cpu_wio (Float32) 0.13 / 0.061 0.39 / 0.099 0.33 / 0.059 0.74 / 0.100 0.80 / 0.107
mgbench disk_free (Float32) 0.11 / 0.065 0.11 / 0.029 0.19 / 0.029 0.41 / 0.079 0.50 / 0.053
mgbench disk_total (Float32) 0.10 / 0.062 0.06 / 0.016 0.17 / 0.021 0.18 / 0.035 0.14 / 0.032
mgbench load_fifteen (Float32) 0.13 / 0.063 0.30 / 0.086 0.29 / 0.051 0.72 / 0.094 0.81 / 0.102
mgbench load_five (Float32) 0.13 / 0.059 0.41 / 0.115 0.32 / 0.067 0.94 / 0.102 1.02 / 0.118
mgbench load_one (Float32) 0.14 / 0.064 0.41 / 0.117 0.34 / 0.063 0.93 / 0.105 1.09 / 0.116
mgbench mem_buffers (Float32) 0.13 / 0.066 0.24 / 0.076 0.25 / 0.052 0.76 / 0.131 0.89 / 0.099
mgbench mem_cached (Float32) 0.13 / 0.061 0.24 / 0.074 0.25 / 0.054 0.68 / 0.110 0.83 / 0.094
mgbench mem_free (Float32) 0.13 / 0.059 0.35 / 0.122 0.25 / 0.062 1.04 / 0.109 1.20 / 0.122
mgbench mem_shared (Float32) 0.10 / 0.065 0.07 / 0.014 0.16 / 0.021 0.12 / 0.022 0.07 / 0.021
mgbench part_max_used (Float32) 0.10 / 0.059 0.07 / 0.015 0.17 / 0.022 0.27 / 0.057 0.29 / 0.040
mgbench swap_free (Float32) 0.11 / 0.056 0.10 / 0.024 0.18 / 0.029 0.33 / 0.064 0.39 / 0.046
weather averageWindSpeed (Float32) 0.42 / 0.255 0.29 / 0.066 0.74 / 0.088 0.54 / 0.089 0.32 / 0.087
weather elevation (Float32) 0.44 / 0.257 0.28 / 0.069 0.80 / 0.106 1.73 / 0.321 1.12 / 0.215
weather maxWindSpeed (Float32) 0.43 / 0.240 0.29 / 0.063 0.80 / 0.087 0.54 / 0.090 0.32 / 0.081
weather precipitation (Float32) 0.56 / 0.256 1.26 / 0.348 1.26 / 0.168 3.11 / 0.542 2.06 / 0.372
weather snowDepth (Float32) 0.44 / 0.243 0.35 / 0.081 0.77 / 0.092 1.00 / 0.192 0.64 / 0.124
weather snowfall (Float32) 0.45 / 0.252 0.37 / 0.096 0.79 / 0.098 1.09 / 0.220 0.74 / 0.151
weather tempAvg (Float32) 0.46 / 0.275 0.32 / 0.070 0.75 / 0.093 0.58 / 0.096 0.35 / 0.090
weather tempMax (Float32) 0.52 / 0.239 0.84 / 0.185 0.87 / 0.114 1.65 / 0.216 1.11 / 0.221
weather tempMin (Float32) 0.50 / 0.226 0.84 / 0.191 0.86 / 0.111 1.59 / 0.206 1.10 / 0.226
sensors humidity (Float32) 0.18 / 0.086 0.77 / 0.196 0.33 / 0.062 1.54 / 0.152 1.46 / 0.149
sensors lat (Float32) 0.18 / 0.086 0.71 / 0.177 0.39 / 0.080 1.54 / 0.141 1.68 / 0.179
sensors lon (Float32) 0.19 / 0.100 0.73 / 0.183 0.39 / 0.090 1.58 / 0.152 1.52 / 0.185
sensors pressure (Float32) 0.19 / 0.090 0.45 / 0.171 0.35 / 0.087 1.65 / 0.144 1.38 / 0.176
sensors temperature (Float32) 0.19 / 0.086 0.79 / 0.191 0.33 / 0.074 1.74 / 0.186 1.25 / 0.143
taxi distance (Float32) 0.02 / 0.010 0.08 / 0.019 0.03 / 0.007 0.16 / 0.019 0.08 / 0.014
taxi distance (Float64) 0.03 / 0.017 0.10 / 0.027 0.10 / 0.008 0.21 / 0.023 0.19 / 0.024
taxi dropoff_lon (Float64) 0.03 / 0.018 0.12 / 0.036 0.09 / 0.018 0.25 / 0.017 0.18 / 0.015
taxi fare (Float64) 0.03 / 0.017 0.08 / 0.029 0.08 / 0.007 0.14 / 0.022 0.12 / 0.013
taxi pickup_lat (Float64) 0.03 / 0.016 0.12 / 0.038 0.09 / 0.018 0.25 / 0.017 0.21 / 0.015
taxi pickup_lon (Float64) 0.03 / 0.018 0.12 / 0.035 0.09 / 0.017 0.24 / 0.016 0.18 / 0.015
taxi tip (Float64) 0.03 / 0.017 0.10 / 0.026 0.11 / 0.007 0.16 / 0.022 0.10 / 0.016
taxi total (Float32) 0.02 / 0.009 0.08 / 0.017 0.03 / 0.007 0.19 / 0.021 0.08 / 0.016
taxi total (Float64) 0.03 / 0.017 0.10 / 0.028 0.09 / 0.008 0.20 / 0.024 0.12 / 0.018
Column NONE ZSTD(3) ALP PCO Wallaby
synthetic cumsum (Float64) 0.04 / 0.025 0.14 / 0.045 0.13 / 0.024 0.20 / 0.037 0.30 / 0.023
synthetic f32in64 (Float64) 0.04 / 0.025 0.17 / 0.056 0.12 / 0.026 0.40 / 0.025 0.23 / 0.023
synthetic fahrenheit (Float64) 0.04 / 0.025 0.12 / 0.035 0.15 / 0.016 0.20 / 0.033 0.25 / 0.037
synthetic gauss (Float64) 0.04 / 0.022 0.15 / 0.041 0.12 / 0.009 0.33 / 0.029 0.17 / 0.019
synthetic mixed2dp (Float64) 0.04 / 0.022 0.20 / 0.052 0.15 / 0.017 0.38 / 0.035 0.18 / 0.025
synthetic mon (Float64) 0.04 / 0.024 0.08 / 0.048 0.14 / 0.026 0.39 / 0.028 0.31 / 0.047
synthetic ms (Float64) 0.04 / 0.023 0.13 / 0.044 0.12 / 0.012 0.16 / 0.023 0.13 / 0.019
synthetic mul001 (Float32) 0.05 / 0.025 0.19 / 0.056 0.12 / 0.031 0.45 / 0.041 0.35 / 0.035
synthetic mul01 (Float64) 0.04 / 0.023 0.18 / 0.050 0.13 / 0.012 0.35 / 0.028 0.16 / 0.020
synthetic prices2dp (Float64) 0.04 / 0.025 0.19 / 0.042 0.14 / 0.014 0.37 / 0.035 0.15 / 0.023
synthetic randbits (Float64) 0.04 / 0.023 0.05 / 0.024 0.11 / 0.024 0.33 / 0.024 0.24 / 0.024
synthetic randwalk3dp (Float64) 0.04 / 0.024 0.16 / 0.041 0.12 / 0.011 0.39 / 0.028 0.13 / 0.021
synthetic repeats (Float64) 0.03 / 0.023 0.02 / 0.005 0.09 / 0.005 0.05 / 0.007 0.03 / 0.006
synthetic rnd (Float64) 0.04 / 0.023 0.09 / 0.052 0.14 / 0.027 0.35 / 0.034 0.15 / 0.032
synthetic rtn (Float64) 0.04 / 0.024 0.15 / 0.044 0.13 / 0.012 0.42 / 0.031 0.14 / 0.024
synthetic seq (Float64) 0.04 / 0.023 0.08 / 0.049 0.13 / 0.024 0.13 / 0.015 0.13 / 0.015
synthetic sine2dp (Float32) 0.05 / 0.024 0.20 / 0.055 0.09 / 0.017 0.55 / 0.055 0.29 / 0.038
synthetic sine2dp (Float64) 0.04 / 0.023 0.17 / 0.042 0.12 / 0.010 0.41 / 0.034 0.20 / 0.020
synthetic sinexp (Float64) 0.04 / 0.022 0.08 / 0.051 0.13 / 0.027 0.34 / 0.035 0.31 / 0.038
synthetic smooth (Float32) 0.05 / 0.024 0.10 / 0.047 0.10 / 0.023 0.32 / 0.034 0.31 / 0.043
synthetic smooth (Float64) 0.04 / 0.023 0.08 / 0.050 0.12 / 0.025 0.57 / 0.030 0.33 / 0.030
synthetic sparse (Float64) 0.03 / 0.023 0.03 / 0.008 0.09 / 0.006 0.11 / 0.028 0.11 / 0.016
synthetic special (Float64) 0.04 / 0.021 0.18 / 0.045 0.13 / 0.013 0.38 / 0.033 0.21 / 0.026
synthetic thirds (Float64) 0.04 / 0.023 0.16 / 0.046 0.14 / 0.026 0.34 / 0.029 0.21 / 0.019

Robustness. The decoder validates all lengths, counts and indices, checks the final ANS states, does not depend on padding after the compressed data, and throws CANNOT_DECOMPRESS on anything inconsistent. The standalone harness built from the production source with ASan and UBSan round-trips every block of the corpus at block sizes of 37, 517, 65536 and 300000 bytes, and decodes about a million truncated, bit-flipped and spliced blocks without a report. The unit tests cover round trips of series, sizes, tails and special values, the sizes of what the codec is made for, truncation, corruption and malformed headers, and they pin the format with 13 fixed blocks (every chunk mode and front-end) that are decoded independently of the current encoder; wallaby_decompress_fuzzer covers the decoder in CI.

Patent note. The mantissa-erasure preprocessing shared by Elf, Elf+, SElf* and Kangaroo is covered by patent US 12,289,120 B2 (Chongqing University, granted 2025-04-29), including the decompression side; Wallaby does not implement it. The building blocks are prior art or openly licensed: integerization of decimals (ALP, MIT), division and multiplication modes (the idea behind pcodec's FloatMult, Apache-2.0; the implementation here is original), differencing, dictionaries, and tANS (Jarek Duda, public domain; the table construction follows the published FSE scheme). No code is taken from pcodec; the on-disk format is original.

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added the experimental Wallaby lossless compression codec for Float32 and Float64 columns. It turns the values into integers (decimals and other rational grids, or bit patterns), removes what is predictable with differences, and codes the rest with an entropy coder whose alphabet is fitted to the block. On the tested real-world columns it is smaller than both ALP and PCO. Gated behind the enable_wallaby_codec setting.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/113575]

robot-clickhouse and others added 2 commits August 5, 2026 21:03
Adaptive lossless codec for `Float32` and `Float64`: splits data into
1024-value blocks and per block picks the cheapest of constant collapse,
integerization with frame-of-reference or zigzag-delta `FFOR` packing,
XOR against a ring of 32 recent reference values, or raw storage.

Motivated by the evaluation of `Chimp` (#66467) and the recent
floating-point compression literature: ALP (SIGMOD 2024), Elf
(VLDB 2023), Camel (SIGMOD 2025) and Kangaroo (SIGMOD 2026,
https://doi.org/10.1145/3802076). The codec deliberately avoids the
decimal-precision mantissa erasure technique of the Elf family and of
Kangaroo, which is covered by patent US 12,289,120 B2; all building
blocks used here are prior art: Gorilla XOR, Chimp128-style windowed
references with an explicit index, ALP-style integerization, and
delta/zigzag/run-length encoding.

Co-Authored-By: Claude Fable 5 <[email protected]>
Three changes to the XOR encoding after benchmarking against `ALP`,
`Gorilla`, `FPC` and the `Chimp` proposal from #66467:

- A per-vector flag omits the trailing-zero field when sampled XOR
  residues have almost no trailing zeros (typical for full-precision
  doubles), where the field was pure overhead.
- The encoder replaces the full ring scan with two O(1) probes (the
  predecessor and a high-bits hash table) and bails out to the RAW
  mode early on incompressible data; compression of incompressible
  data got 10x faster and now matches `NONE`.
- The reference ring grows from 32 to 64 values with a 6-bit index,
  which covers longer periodicity in the data.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov
alexey-milovidov requested a review from a team as a code owner August 5, 2026 21:23
@mintlify

mintlify Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Nov 24, 2026, 5:17 PM

Conflict resolution notes:
- `SZ3` took method byte 0x9d and `Quantized`/`ZXC` took 0x9e/0x9f on
  master, so `Wallaby` moves to 0xa0 (nothing was written with the old
  byte outside local experiments).
- `docs/en` was removed on master (legacy Docusaurus documentation);
  the `Wallaby` section stays only in
  `docs/reference/statements/create/table.mdx`.
- `01222_system_codecs.reference` gets the `Wallaby` row with method
  byte 160 next to the new `Quantized`/`SZ3`/`ZXC` rows, 18 codecs
  in total.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e2c5d03]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) FAIL
Server died FAIL cidb
UndefinedBehaviorSanitizer: signed integer overflow (STID: 1003-46d8) FAIL cidb
Stateless tests (amd_asan_ubsan, flaky check) FAIL
Server died FAIL cidb
UndefinedBehaviorSanitizer: undefined behavior (STID: 1003-46d8) FAIL cidb
Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) FAIL
Server died FAIL cidb
UndefinedBehaviorSanitizer: signed integer overflow (STID: 1003-46d8) FAIL cidb
Unit tests (asan_ubsan) FAIL
Fast test (arm_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (wasm64) DROPPED
Build (arm_fuzzers) DROPPED
Integration tests (arm_binary, distributed plan, targeted) DROPPED
Integration tests (amd_tsan, targeted) DROPPED

AI Review

Summary

Wallaby adds an experimental lossless codec for Float32 and Float64, with integerization, prediction, and entropy coding. Reviewed head e2c5d031da6d, including the version-2 rewrite and prior discussion. One existing test-portability finding remains; no new production-code defects were identified.

Findings

⚠️ Majors

  • src/Compression/tests/gtest_compressionCodec.cpp:3422: MalformedHeaders compares serialized little-endian output with native Float64 storage. On a big-endian host, each decoded 1.5 is 00 00 00 00 00 00 f8 3f, while the expected memory contains 3f f8 00 00 00 00 00 00, so the test fails despite correct decoding. Compare against bytes produced by seriesBytes<Float64>, or load decoded values with unalignedLoadLittleEndian<Float64>. The helpers fixed in the latest commit are correct, but this comparison retains the same endian assumption. Existing thread; replied once to the fix claim.
Tests
  • ⚠️ Verify WallabyTest.MalformedHeaders on a big-endian host or emulator after correcting the comparison. The current Fast test report lists all five Wallaby stateless tests as passing, but does not demonstrate big-endian execution. No local tests or builds were run in this review job.
Final Verdict

Status: ⚠️ Request changes

Correct the remaining native-order comparison in MalformedHeaders.

Findings from benchmarking on real data (mgbench machine metrics,
the environmental sensors dataset, NOAA weather):

- Real gauge columns interleave many sources, so neighboring values
  are unrelated while equal and similar values recur hundreds of rows
  apart. The reference ring grows to 256 values (8-bit index) and the
  encoder gains two more O(1) probes: a whole-value hash that finds an
  equal ring value for the EQUAL branch (low-cardinality columns), and
  a low-bits hash that finds a reference producing an XOR result with
  many trailing zeros. The trailing-field elision decision now also
  estimates low-bits collisions, so it does not throw away the field
  where such references exist.
- The threshold above which the XOR encoding is tried in addition to
  a successful decimal packing was calibrated for `Float64` and left
  `Float32` vectors on near-raw 31-bit packings; it now scales with
  the value width. This alone shrank the mgbench `load_one` column
  from 101 MB to 72 MB, ahead of all other floating-point codecs.
- One high-precision sample must not force a huge decimal scale onto
  a whole vector: when quantization with the largest sampled scale
  degenerates, the median sampled scale is tried before giving up.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Speed comparison on the real datasets (same columns as the size table in the description; throughput in MB/s of uncompressed data, single thread, on a loaded shared server — treat small differences as noise. INSERT is the best of 3 runs; SELECT is sum(x), mean of 20 scans).

Compression (INSERT), MB/s:

Column LZ4 ZSTD(3) Gorilla FPC ALP Chimp Wallaby
mgbench load_one 230 177 257 263 194 187 141
mgbench cpu_user 241 191 254 265 179 177 148
mgbench mem_free 262 200 261 269 187 201 156
sensors temperature 188 62 38 17 151 146 202
sensors humidity 169 154 127 270 236 191 251
sensors pressure 241 125 68 54 80 217 134
weather temp_max 462 352 483 399 353 306 523
weather precipitation 144 207 112 136 249 193 407
geometric mean 228 166 153 150 189 198 216

Decompression (SELECT scan), MB/s:

Column LZ4 ZSTD(3) Gorilla FPC ALP Chimp Wallaby
mgbench load_one 1489 1040 726 677 2169 466 558
mgbench cpu_user 1684 1152 846 708 2079 548 662
mgbench mem_free 1746 944 804 747 2281 517 634
sensors temperature 1300 871 724 605 2221 389 1478
sensors humidity 1352 864 735 665 2440 416 1561
sensors pressure 2721 1024 722 659 1626 443 781
weather temp_max 2205 2140 1341 710 3237 714 3939
weather precipitation 1872 1248 902 701 2754 597 2575
geometric mean 1746 1111 832 683 2309 502 1199

Reading of the results:

  • On compression speed, Wallaby has the best geometric mean of the specialized codecs (216 MB/s), close to LZ4. It is fastest overall on the NOAA columns, where the decimal modes vectorize; the mgbench columns take its XOR path with three hash probes per value, which costs ~40% against Gorilla/FPC there.
  • On decompression, ALP remains the fastest overall, as expected from its fully vectorized design — this matches its own paper and Kangaroo's §6.6. Wallaby is the second-fastest specialized codec (2.4x Chimp, 1.4x Gorilla, 1.8x FPC on the geometric mean) because its decimal-mode blocks decode through the same FFOR unpacking as ALP; on weather temp_max it is the fastest codec in the whole table (3.9 GB/s) while also being the smallest float codec there. Columns that fall back to the XOR path (mgbench, pressure) decode serially at ~600-800 MB/s — faster than the whole XOR family, slower than ALP.
  • Combined with the size table in the description: on 6 of 8 real columns Wallaby simultaneously holds the best float-codec compression ratio and a top-2 float-codec scan speed.

The low Gorilla/FPC insert numbers on some sensors columns are likely interference from the shared server despite best-of-3; don't read too much into any single cell.

- Initialize the scratch buffers flagged by
  `cppcoreguidelines-pro-type-member-init`; the three per-vector
  buffers on the compression path that are always filled before use
  keep a `NOLINT`, matching how `CompressionCodecALP.cpp` handles the
  same pattern, because zeroing them per vector is a measurable cost.
- `decodeXor` now checks the remaining bit count before every read:
  `BitReader` silently produces zero bits past the end of the buffer,
  so a truncated XOR payload used to synthesize garbage values instead
  of throwing; now it deterministically throws `CANNOT_DECOMPRESS`.
- `doDecompressData` now rejects payloads with leftover bytes after
  the last vector and the trailing remainder, instead of silently
  accepting appended junk.

The last two address the review comments.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Compression/CompressionInfo.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e2c5d031d with master b83bf296e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

8 object files changed (+482.63 KiB total), 2 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_compression.dir/Compression/Wallaby.cpp.o new 399.30 KiB +399.30 KiB
src/CMakeFiles/clickhouse_compression.dir/Compression/CompressionCodecWallaby.cpp.o new 79.05 KiB +79.05 KiB

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

785 translation units recompiled, 5431 s compile time in total, 783 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse DB::Wallaby::(anonymous namespace)::log2Table()::table new 128.02 KiB +128.02 KiB
programs/clickhouse DB::Wallaby::(anonymous namespace)::xlog2xTable()::table new 128.02 KiB +128.02 KiB
programs/clickhouse DB::Wallaby::(anonymous namespace)::layoutFolding()::folding new 85.60 KiB +85.60 KiB

Job report

@rienath rienath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also benchmark PCO #110613 compression ratio + [de]compression speed and add it to the tables above. It'd interesting where Wallaby sits in these metrics compared to ALP and PCO

… document the method byte

The `decodeXor` function now verifies that the declared payload was fully
consumed: after decoding all values, fewer than 8 bits may remain and all
of them must be zero (the encoder pads only with zero bits), so an inflated
`payload_size` hiding junk bytes raises `CANNOT_DECOMPRESS`.

Also add the `0xa0` method byte of `Wallaby` to the `NativeFormat` spec,
matching the existing `SZ3`/`Quantized`/`ZXC` experimental-codec entries,
and rename the `quantizeAll` lambda to `quantize_all` for naming consistency.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @rienath Here is the requested comparison with PCO (#110613). Since the exact synthetic generators and datasets from the description tables were produced on a different machine, I re-measured all codecs from scratch on one machine with a single binary containing both Wallaby and the PCO codec from #110613 (10M Float64 values per dataset, clickhouse local, max_threads = 1, size after OPTIMIZE FINAL, INSERT best of 3, SELECT sum(x) mean of 10 runs; generator expressions listed below).

Dataset ZSTD(3) Gorilla FPC ALP PCO Wallaby
sine + 2dp noise — size 33.5 MB 81.9 MB 68.7 MB 22.7 MB 11.4 MB 15.2 MB
— insert / select, s 0.43 / 0.098 0.18 / 0.092 0.15 / 0.078 0.32 / 0.018 10.60 / 1.222 0.12 / 0.024
random walk 3dp — size 32.6 MB 66.0 MB 64.1 MB 20.0 MB 14.6 MB 13.9 MB
— insert / select, s 0.43 / 0.085 0.16 / 0.081 0.15 / 0.076 0.31 / 0.019 9.55 / 0.925 0.11 / 0.023
prices 2dp (no smoothness) — size 41.2 MB 72.5 MB 74.7 MB 25.16 MB 25.8 MB 25.17 MB
— insert / select, s 0.47 / 0.104 0.17 / 0.084 0.15 / 0.085 0.33 / 0.019 8.42 / 0.809 0.11 / 0.027
repeats (runs of 100k) — size 0.06 MB 1.30 MB 5.04 MB 0.39 MB 0.07 MB 0.32 MB
— insert / select, s 0.08 / 0.013 0.08 / 0.017 0.13 / 0.056 0.25 / 0.013 1.04 / 0.197 0.07 / 0.010
smooth gauge (full precision) — size 74.5 MB 66.6 MB 54.4 MB 70.2 MB 15.5 MB 58.8 MB
— insert / select, s 0.19 / 0.092 0.16 / 0.085 0.15 / 0.077 0.31 / 0.032 12.96 / 0.908 2.53 / 0.073
real doubles (sin×exp) — size 78.6 MB 82.5 MB 73.9 MB 80.1 MB 64.1 MB 78.3 MB
— insert / select, s 0.58 / 0.095 2.23 / 0.093 0.29 / 0.079 0.38 / 0.022 10.90 / 0.831 0.34 / 0.123
random bits (incompressible) — size 80.0 MB 82.5 MB 85.0 MB 80.1 MB 80.0 MB 80.0 MB
— insert / select, s 0.12 / 0.024 0.18 / 0.091 0.15 / 0.082 0.26 / 0.023 7.22 / 0.022 0.16 / 0.023

PCO(0) (lowest level, default is PCO(8) = the pco crate default) on two of the datasets, for the speed/ratio trade-off: sine + 2dp noise — 21.5 MB, 2.34 s insert, 0.908 s select; smooth gauge — 67.3 MB, 1.54 s insert, 0.470 s select.

Reading of the results:

  • Ratio. PCO at its default level has the best compression ratio on 4 of the 7 datasets, and by a large margin on high-precision data (smooth gauge: 15.5 MB vs 54.4 MB for the next-best FPC; real doubles: 64.1 vs 73.9 MB) — as expected, since pco entropy-codes with tANS while everything else here is bit-packing. Wallaby wins on the delta-friendly random walk and effectively ties ALP/PCO on prices.
  • Speed. In the current Add PCO compression codec (linking the pcodec Rust crate) #110613 implementation, PCO compresses at ~6–11 MB/s (20–100× slower than Wallaby/ALP/Gorilla) and decompresses at ~65–100 MB/s uncompressed throughput — ~40× slower than Wallaby/ALP scans on decimal data and ~10× slower than the Gorilla/FPC family. Lowering the level to PCO(0) helps compression speed ~5× but leaves decompression unchanged. The pco crate upstream reports hundreds of MB/s, so a good part of this is likely fixable per-block/FFI overhead in the codec integration rather than the format itself — worth profiling in Add PCO compression codec (linking the pcodec Rust crate) #110613. But the format is entropy-coded, so even upstream speeds stay well below the several-GB/s bit-packed scans of ALP/Wallaby.
  • In short: PCO sits at the "best ratio, slowest" end (a specialized-float analog of ZSTD(high level)), ALP/Wallaby at the "fast scan" end, with Wallaby taking the ratio lead among the fast codecs on smooth/delta-friendly decimal data.

Generator expressions (10M rows each, x is the expression over number): sine + 2dp noise round(sin(number / 100.) * 1000 + ((cityHash64(number) % 1000) / 1000.), 2); random walk 3dp round(sum(((cityHash64(number) % 2001) - 1000) / 1000.) OVER (ORDER BY number), 3); prices 2dp round(100 + ((cityHash64(number) % 1000000) / 100.), 2); repeats round(sin(intDiv(number, 100000)) * 1000, 2); smooth gauge sin(number / 10000.) * 100 + cos(number / 777.); real doubles sin(number / 100.) * exp(number % 40); random bits reinterpretAsFloat64(reinterpretAsFixedString(cityHash64(number))). Machine differs from the description tables, so absolute numbers are not comparable across the two; the codec-vs-codec relations within this table are.

One coordination note found while building the combined binary: this PR and #110613 both claim method byte 0xa0 in CompressionMethodByte — whichever merges second needs to move to 0xa1 (I used 0xa1 for PCO locally to run this comparison).

The early bailout in the `Wallaby` XOR encoder compared the bits written
so far against a per-value budget, so an incompressible prefix could
abandon the XOR encoding even when a run-collapsible suffix would still
have made it far cheaper than the RAW mode, violating the "pick the
cheapest encoding per vector" contract.

The encoder now precomputes, for every position, how many of the
remaining values differ from their predecessor. Each such value costs at
least the cheapest single-value branch (the EQUAL branch: selector, tag
and ring index, 11 bits), while repeated values can collapse into runs,
so the encoding is abandoned only when even this lower bound cannot
beat the RAW mode. On purely incompressible data the bailout now
triggers near the end of the vector instead of after 256 values, which
costs about 2x on that path (240 MB/s single-threaded, still above the
XOR-family codecs); mixed blocks of incompressible values and runs now
compress at 2.1 bytes per value instead of falling back to RAW.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI failure attribution for the latest run:

  • AST fuzzer (amd_debug, targeted, old_compatibility) — Logical error: 'database_name != "_temporary_and_external_tables"' is unrelated to this PR: it fails across many PRs and on master daily (per CIDB), and the fix is already in progress in Do not read the internal database of temporary tables in Merge #113224 (Merge reading the internal database of temporary tables).
  • Performance Comparison (arm_release, master_head, 5/6) — decimal_aggregates #17 failed in both ::old and ::new, i.e. the master binary shows the same behavior, so it is an unstable query on that shard, not a regression from this PR (this PR only adds a new experimental codec that no existing perf test uses). Related: Unstable performance tests: 61 tests show >10% noise in >10% of master runs #100759

@rienath rienath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Having looked at both tables together, I don't think Wallaby clears the bar. Ratio-focused users are better served by ZSTD(3)/PCO on all 8 real columns; speed-focused users get faster selects from ALP on every dataset measured (~25% on decimal, 2–5× on non-decimal). What's left is a size edge over ALP that is −22–29% on columns where both trail ZSTD(3) by 1.5–2.5× (so nobody size-conscious would use either), but only −2…6% where the fast family is actually competitive — the win is concentrated exactly where the codec is the wrong choice. Combined with the pathological encode case and a fifth permanent float format, I'd close this, and record the one durable finding — delta-over-integerized values buys ~25% on real monitoring data — in an issue for the future.

@rienath

rienath commented Aug 7, 2026

Copy link
Copy Markdown
Member

I think we should continue with PCO and not continue with Wallaby. From the data provided above, Wallaby doesn't have an edge worth pursuing. It's possible that next iteration of this family of algorithms will, we could consider them.

Please reopen this PR and ping me if you have data that contradicts or disagree.

@rienath rienath closed this Aug 7, 2026
@rienath rienath self-assigned this Aug 7, 2026
# Conflicts:
#	src/Client/BuzzHouse/Generator/FuzzConfig.cpp
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status 2026-11-11: merged master (2202f390357) and pushed e7259ff553b. The only conflict was the BuzzHouse codec list in src/Client/BuzzHouse/Generator/FuzzConfig.cpp: master added PCO and this PR adds Wallaby, so the list now has both. The binary builds. 01222_system_codecs and all six Wallaby stateless tests pass locally.

CI on the previous head 621750dbe24 was green, and there are no unresolved review threads. @rienath's CHANGES_REQUESTED review recommends closing the PR on design grounds, and the latest maintainer comment sets the bar: accept it only if Wallaby is meaningfully better than both ALP and PCO. That decision needs a human, so this pass made no design changes.

# Conflicts:
#	tests/queries/0_stateless/01222_system_codecs.reference
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status 2026-11-18: merged master (3634df08ebb) and pushed 4e3131d9855. The only conflict was in 01222_system_codecs.reference: master promoted ZXC to Beta and this PR adds the Wallaby row, so the merged file keeps the Beta tier and the count of 20. The binary builds. 01222_system_codecs and all six Wallaby stateless tests pass locally.

There are no unresolved review threads. @rienath's CHANGES_REQUESTED review (which recommends closing) and the bar set earlier (Wallaby must be meaningfully better than both ALP and PCO) are still open. A human needs to make that design decision.

clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 18, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status 2026-11-20: pushed aedb3df0ca6.

  • Fixed: the settings_changes_history style check failed on e4ccae308a5 because master bumped the version to 26.12 and the enable_wallaby_codec record was still under 26.11 (the setting was never released there). The record is now under 26.12; python3 -m ci.jobs.scripts.settings_history --base origin/master passes locally.
  • No unresolved review threads. The CHANGES_REQUESTED review (which recommends closing on design grounds) and the bar of being meaningfully better than both ALP and PCO still need a human decision.

clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 20, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status 2026-11-20: merged master (e5baeaed352, no conflicts, the PR's own diff is unchanged) and pushed c79cdc8b78a. The binary and unit_tests_dbms build; the codec gtests, 01222_system_codecs and all six Wallaby stateless tests pass locally, and the settings-history check passes.

The only red on aedb3df0ca6 was CH Inc sync (tests failed). The private failures are unrelated to this PR: UBSan applying non-zero offset 8 to null pointer in unique_ptr.h inside distributed-cache server instances (test_distributed_cache/* in three Integration tests (amd_asan_ubsan, db disk) shards), and 03000_shared_merge_tree_select_1 failing in CREATE TABLE on a SharedMergeTree keeper commit conflict. None of them uses the Wallaby codec. The merge re-triggers the sync run.

There are no unresolved review threads. The CHANGES_REQUESTED review, which asks whether Wallaby is better enough than ALP/PCO to justify it, is still a maintainer design decision.

alexey-milovidov and others added 16 commits November 20, 2026 20:00
The previous `Wallaby` bit-packed its integers and fell back to XOR, so `PCO` produced smaller data on most
columns. The codec is rewritten around an entropy coder so that it compresses better than both `ALP` and `PCO`:

- Front-ends, chosen per chunk of up to 16384 values by measuring: bit patterns with the common trailing zeros
  removed; division by a denominator (decimals, and other rational grids such as averages of decimals over 60
  samples, found by continued fractions and by trying small multiples of powers of ten); multiplication by a
  constant (values that were produced by one, which are not correctly rounded decimals). `Float32` values can
  be reconstructed in single precision. Values that are slightly off the grid get adjustments (a distance in
  the order of bit patterns); values with no integer (`NaN`, infinities) are exceptions, removed from the
  sequence and coded separately.
- Prediction: differences of order up to 7 with an optional center, after removing a common divisor.
- Entropy coding with tANS (4 interleaved states): the alphabet mixes dictionary symbols for frequent exact
  values with logarithmic or fixed-width bins, zero runs are symbols of their own, and the frequencies can
  depend on the magnitude of an earlier token. The model is described by a few parameters, so the header of a
  chunk stays small on blocks of a few thousand values.

The implementation lives in `src/Compression/Wallaby.cpp`; `CompressionCodecWallaby.cpp` is the codec glue.
The decoder validates all lengths and indices, does not depend on padding after the compressed data, and was
run under ASan and UBSan over hundreds of thousands of truncated and corrupted blocks.

The unit tests of the old byte format and the regression tests of the old scale chooser are replaced by tests
of the new format; the format is described at the top of `Wallaby.cpp`.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The encoder compared candidates (front-end and differencing order) by a sampled analysis that guesses the
gain of the dictionary; measured against the final size, that guess is off by 10-14% on dictionary-heavy
streams, which picked the wrong candidate in 12% of the chunks of a longitude column and cost up to 1% of
the size. `StreamEncoder::finalize` is now split in two stages: `count` (bins, dictionary, the alphabet and
the counts of its tokens; its estimate is within about 1% of the final size) and `complete` (tokens,
contexts, frequencies, the header of the model). Candidates are ranked by `count`; only the winner is
completed, the runner-up only when the two are within 0.3%, and the stream of adjustments only when it is
going to be written.

Other changes to the encoder, none of which changes the format:

- Frequencies are normalized with a table of logarithms and an array heap instead of `std::priority_queue`
  and `log2` per symbol; same result.
- All the context trials are counted in one pass over the tokens; the token pass has no unpredictable
  branch on the kind of the token; the counts of the tokens are derived without making the tokens.
- Exact values of a narrow range are counted in an array indexed by the value instead of a hash table; the
  hash table starts with the large size when the sample predicts an overflow of the small one.
- The size of the ANS table is chosen with the size of the frequencies in the header taken into account.
- The second conversion with a finer denominator is checked on the sample of inexact values first.
- The bit patterns are not tried when the integers are much narrower than the mantissa and only a few
  values are exceptions; higher differencing orders are not tried when the first one is far behind.

On the sampled corpus of 71 columns the sizes change by -0.08% in total (no column is worse by more than
0.2%), and the encoder is 15-35% faster on `Float32` columns with many repeated values.

Also fix `WallabyTest.RoundTripOfSizesAndTails`, which fed an empty block to the generic part of the codec.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The analysis of a stream looks at stripes of 256 values and counted zero runs within them, so a long run
looked like many short ones, and coding one token per zero was estimated to be smaller. A chunk of long
plateaus (for example the elevation of weather stations, whose differences are almost all zero) was coded
with 16384 tokens instead of a few.

Now a run is counted where it begins, with its whole length, and very long runs are preferred when the two
sizes are about the same: they make few tokens, which are much faster to code in both directions, and need a
smaller ANS table. The counting of distinct values skips a value that repeats the previous one, which removes
a chain of dependent updates of the same word on such data.

On the sampled corpus of 71 columns no column gets larger by more than 0.02%; columns with long runs get up
to 12% smaller, up to 2.9x faster to compress and up to 2.7x faster to decompress. The format does not change.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Conflict in `src/Client/BuzzHouse/Generator/SessionSettings.cpp`: `Wallaby` stays in the pool of codecs for
floating-point columns, and `SZ3` is added only for lossy tables as on master.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The encoder worked on 64-bit integers for both types, so a block of `Float32` (16384 values) went through
twice the memory per value in every pass. `StreamEncoder` is now a template on the type of its values, and
`Encoder<Float32>` keeps the latents, the adjustments, the residuals, the hash keys and the raw bits in 32
bits.

The differences of bit patterns of floats of opposite signs do not fit into 32 bits, so the arithmetic on the
latents of `Float32` is defined to be modulo 2^32. The decoder already truncated the bit patterns to the
width of the float; it now also reads the latent of the DIV and MUL front-ends as a signed 32-bit number.
The format is otherwise unchanged and its description is updated. The integers of the decimal front-end of
`Float32` are limited to 2^31.

On the sampled corpus all the round trips are bit-exact, three columns change their size by 0.01%, and the
encoder is about 5-10% faster on `Float32` columns; the ASan and UBSan harness passes at four block sizes.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Evaluating a candidate took three or four passes over the values: a sampled analysis, the bins of every
value, a hash table for the dictionary, and the tokens. Now the exact values are counted first, in an
array indexed by the value when the range is narrow, or in a hash table when a sample has repeated values,
and the rest comes from the distinct values:

- With few distinct values (a quarter of the chunk at most) the statistics for the choice of the bins are
  made from them: exact instead of sampled, and cheaper.
- The counts of the bins and the token of every value come from the slots of the values, without computing
  the bin of every value again.
- The zero runs of a counted stream are found once, from a bit mask of the zeros, and reused for the
  statistics, for the counts of the run tokens and for the token pass.

Also: the classes of every pair of parameters of the logarithmic bins are folded from one table computed
once per process; repeated values of the sample are found with a small hash set instead of a sort;
frequencies are scaled without a division per symbol; an Exp-Golomb code is one write; the bits of four
tokens are written at once; the ANS states stay in registers; the dictionary of 32-bit values is sorted as
packed integers. These keep the output byte-identical.

On the sampled corpus of 71 columns the sizes change by -0.02% in total (24 columns smaller, 5 larger by at
most 0.16%), all the round trips are bit-exact, and the encoder is 15-30% faster on `Float32` columns than
before the 32-bit latents. The format does not change.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The first CI run on this branch after the merge with master stopped at the style check and at `clang-tidy`:

- `std::vector` is not allowed in `src/Compression`: the scratch buffers of the encoder and of the decoder
  are `VectorWithMemoryTracking` now, and the tables that are made once per process (logarithms, the folding
  of the classes) are plain arrays.
- `clang-tidy` (51 diagnostics in `Wallaby.cpp`): `[[nodiscard]]` on the getters, initialized locals and
  members, one declaration per statement, range-based loops, `floor` for rounding, a redundant condition,
  an integer division in a floating-point context.
- `clang-tidy` in the unit tests: `NOLINT` for the constant seeds, as in the other tests of the file, and
  no integer division in a floating-point context.

The output of the codec does not change.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113575&sha=0f8da52720f1a4c103117839603002e744bf6440&name_0=PR
#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ch merged with master

The work continued on the previous base to keep a local build; this brings it on top of the merge with master.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…search

- The conversion of floats to integers is a pass without branches and without dependencies between the
  values (it can be vectorized); the adjustments are computed in a second pass only for the chunks where
  some values are not reproduced exactly.
- The search of the differencing order takes the median of every fourth residual of the sample, makes the
  histogram for the center only when the median is not zero, and stops after the first order when it is no
  better than no differencing.
- The search over the pairs of parameters of the logarithmic bins walks the used classes in sorted order,
  where the classes of every pair are runs: no scratch histogram per pair.
- The key and the count of a distinct value are stored together; the residuals of order 1 are made in one
  pass; the dictionary is chosen with a table of logarithms instead of two divisions per value.

On the sampled corpus of 71 columns the sizes change by -0.002% in total and all the round trips are
bit-exact; the ASan and UBSan harness passes at four block sizes. The format does not change.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The model with zero-run tokens was chosen whenever its estimated size was smaller, even by a fraction of a
percent, and even when the runs were so short and rare that the stream kept 80-100% of its tokens. Such a
stream gains nothing in the encoder and is decoded by the slower path for runs (tokens first, then their
expansion).

Now runs that remove less than a quarter of the tokens have to make the stream at least 2% smaller.

On the sampled corpus the sizes grow by 0.04% in total (at most 0.5%, on `mgbench` columns that stay 1-40%
below `PCO`), the affected columns decompress 10-35% faster, and the encoder is about 7% faster at the
median. The format does not change.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A review thread asked for decode tests with fixed bytes, so that the persisted format does not depend on what
the current encoder happens to produce. The goldens that were added for the first format went away with the
rewrite; this adds them for the format version 2.

`WallabyTest.FixedPayloads` has 13 blocks made by the encoder when the format was fixed: a constant chunk,
the division and the multiplication front-ends, `Float32` in single precision, bit patterns, `Float32` bit
patterns of both signs (differences modulo 2^32), exceptions, zero runs, differences of a higher order,
dictionary symbols, contexts, a verbatim block and a tail. Every block is decoded and compared bit-exactly
with values recomputed by the test, and is checked to be rejected without its last byte.

#113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
# Conflicts:
#	src/Compression/tests/gtest_compressionCodec.cpp
The fixed payloads and the output of the decoder are little-endian streams, but `seriesBytes` and `compressAndCheck` in the unit tests built their bytes with a native-order `memcpy`, so `FixedPayloads` would fail on a big-endian host. Both now store every value with `unalignedStoreLittleEndian`. Nothing changes on little-endian hosts.

Addresses the review in #113575

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (the conflict was only in the includes of gtest_compressionCodec.cpp) and addressed the open review thread in e2c5d03.

The two CI failures of the previous commit are not related to the codec:

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113575&sha=377e71a74a798889d8b524863cabdecd0eaaaf9f&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%207%2F8%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Findings for json_extract_rapidjson #0, #1, #6 and #14 (arm, 377e71a74a79): the hot code is identical in both binaries and only its stack placement differs, so there is nothing to fix in the JSON functions or in this PR, and I'm not sending a PR.

  • The four queries are exactly the JSONExtractString queries of the shard (+9.6% to +11.9%, reproduced after the restart). The six JSONExtractInt/UInt/Float/Bool queries of the same run, five of them on the same documents, are at 1.00-1.01x. The reference 6886cedd2c9c is one documentation-only commit behind this PR's base.
  • RapidJSONParser::parse, rapidjson's IterativeParse and ParseString, and ExecutableFunctionJSON<NameJSONExtractString, ...>::executeImpl have identical instructions and frame sizes in both builds. In the #14 CPU profile all of the extra time is in ParseString (215 -> 327 samples); the other three profiles are mostly jemalloc's sampling-profiler unwinding and localize nothing.
  • The difference is the stack depth under the parser. ExpressionActions::execute has a 448-byte frame in the PR build and 464 in the reference (the PR build calls std::vector<Int64, AllocatorWithMemoryTracking>::assign out of line, the reference inlines it), so rapidjson's per-token parsers start at 32 instead of 48 mod 64. Each JSONExtract* function has its own frame (String 8688 B, Float 8704 B, Int/UInt/Bool 8720 B), so one shift puts each family at a different offset. In the Use CPU slots for index analysis threads #133869 run PipelineExecutor::executeImpl grew by 16 bytes instead, Int/UInt/Bool moved from 16 to 32 mod 64, and exactly BaseDaemon: terminate on double SIGINT #3, Error fetching data from materialized view #7, Add Dockerfiles for client and server #8 and Include not found #12 slowed down while the string queries stayed at 0.99-1.00x. In both runs the slow queries are exactly those whose parsers start at 32 mod 64.
  • It is a common per-build mode on arm: over the last 14 days these queries ran at p50 1.000x in about 1300 arm PR runs each, and 16 builds of 8 PRs, this one included, ran a group of them 8-14% slower.

This branch was successfully deployed

1 active deployment
staging - docs — e2c5d031 Deployed Nov 24, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... pr-experimental Experimental Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants