Chronix

Integer, timestamp and dictionary encoding

How Chronix encodes integers, timestamps and strings: delta-of-delta, frame-of-reference bit packing, pcodec timestamps and dictionaries.

On this page

Integers, timestamps and strings each have their own codecs. Timestamps go to pco or delta-of-delta; integers to run-length, frame-of-reference, pco or delta with zigzag; tags to a dictionary; booleans to a bitmap. As with floats, every block tries its candidates on a sample and keeps the smallest (Encoding).

Timestamps

A sampler ticking every second produces deltas of 1 000 000 000 ns, and the deltas of those deltas are zero.

CodecStoresWins on
Delta-of-deltathe first timestamp and delta, then each change of the delta in a variable-length code — one bit when it is zeroperfectly regular clocks
pcothe deltas, entropy-coded against bins learned per chunkreal clocks with jitter

Measured (chronix-encoding/tests/timestamp_codec_check.rs):

SeriesResult
1 s sampler with up to 10 ms of random jitterpco 2.7×, within 5 % of the 2.75× no lossless codec can beat; delta-of-delta 0.9×, larger than plain
Regular with gaps345× (best codec)
Perfectly regular1 092× (best codec)

Jitter is what defeats delta-of-delta: every non-zero change costs a varint, while pco charges only the entropy of the jitter itself. Both decode sequentially; the work per value is an addition.

Integers

CodecStoresWins on
Run-lengthvalue and run lengthconstant stretches: states, flags, setpoints
Frame-of-referenceoffsets from the block minimum, bit-packed at ⌈log₂(max−min+1)⌉ bitsvalues in a narrow range — HTTP status codes take 9 bits
Delta + zigzag + bit-packingdifferences, mapped to unsigned (0, −1, 1, −2 → 0, 1, 2, 3)counters and slow trends
pcoentropy-coded deltasanything else

Unsigned integers have their own frame-of-reference path, so values near the middle of the u64 range do not inflate to 64 bits through a signed reinterpretation.

Decimal columns use these codecs on their i128 mantissas, which is why an exact type compresses better than the float it replaces: 475× on noisy power, 1 040× on a monotone register.

Strings

Tag columns hold few distinct values — regions, hosts, device ids — repeated on millions of rows. A dictionary stores each distinct string once and every row as an index of ⌈log₂ k⌉ bits for k distinct values: two values cost one bit a row, 256 cost eight. The dictionary lines up with Arrow dictionary arrays, so the query engine reads it without rebuilding. Tag columns also carry a bloom filter per row group for pruning (Query execution).

Booleans

Eight values per byte, always 8× against one byte per value. Long runs of the same value are left to the block compressor.

Edit this page on GitHub · Updated

Esc