← Lessons

quiz vs the machine

Platinum1800

System Design

Gorilla Compression

How float values compress with XOR against the previous sample.

6 min read · advanced · beat Platinum to climb

The Gorilla scheme

Gorilla is a compression approach for time series float values, popularized by an in memory store of the same name. It exploits the fact that consecutive values in a series are usually close, so their bit patterns are similar.

XOR against the previous value

Each value is compared to the previous one using a bitwise XOR:

  • If the XOR is zero, the value is identical, stored as a single zero bit.
  • Otherwise the XOR has a block of meaningful bits surrounded by zeros.
  • The scheme records the count of leading and trailing zero bits, then stores only the meaningful middle bits.

Why it works

Floats that drift slowly, like a temperature or a slowly rising counter, share most exponent and high mantissa bits, so the XOR is mostly zeros. Storing only the differing window of bits yields large savings.

Reusing the window

When consecutive XORs share the same leading and trailing zero counts, the scheme reuses the previous window to skip the control bits, compressing even further.

Key idea

Gorilla compresses floats by XOR with the previous value and storing only the meaningful nonzero bit window, which is tiny when values change slowly.

Check yourself

Answer to earn rating on the learn ladder.

1. How does Gorilla compress a float value?

2. If the XOR of two consecutive values is zero, what is stored?

3. Why does Gorilla work well on slowly changing metrics?