shared by every format
Encoding primitives
Five encodings do almost all the work in TSDB's on-disk formats. The first two come from
Go's encoding/binary; the varbit family is Prometheus-specific
bit-level encoding used inside chunks.
- uvarint: unsigned variable-length integer. 7 bits per byte, least-significant group first; the high bit of each byte says "more bytes follow". Values < 128 cost one byte, which is why counts, lengths and small deltas are cheap.
- varint: signed, via zigzag. Signed values are zigzag-mapped
(
0→0, −1→1, 1→2, −2→3…) so small negatives stay small, then uvarint-encoded. Used for timestamps (mint) and deltas that can go negative. - varbit_ts: timestamp delta-of-delta (XOR chunks). Scrapes arrive on a
nearly perfect interval, so the delta-of-delta ("dod") of the timestamp is almost always
zero; a bucketed prefix code from
chunkenc/xor.gospends 1 bit on that case and up to 68 bits on an arbitrary 64-bit jump. - varbit_xor: value compression (XOR chunks). Each value is XORed with the previous one; identical values give XOR = 0 (1 bit), and similar float64s share sign/exponent/leading-mantissa bits, leaving only a narrow "significant" window to store.
- CRC-32C (Castagnoli): the checksum trailer on index, chunks and tombstones files.
The live, interactive versions of these encoders (type a value, see the bits) are in the app, not on this page.