Gorilla compresses the values of a time series by storing the XOR of each value with the value before it.
Most values are close to one another. Server utilization goes from 70 to 60 to 65, or stays at 30.
The XOR of two close values is usually small: 35 and 43 give 8. It is not a subtraction, and it is not always small: 16 and 15 give 31.
What is stored follows from the XOR:
- A zero. A zero is stored.
- Anything else. The value is stored with its leading and trailing zeros.
A series that climbs in equal steps, 32, 36, 40, 44, gives XORs that end in the same zeros. The leading and trailing zeros are consistent across the series. Their counts are noted once, 3 and 1, and only the bits between them are stored.
With this, 51% of all values are compressed to one bit. The rest fall in small ranges that take a few bits: some take 8, fewer take 10, and the last take 32.