Skip to content

Latest commit

 

History

History
51 lines (42 loc) · 2.6 KB

comparison.md

File metadata and controls

51 lines (42 loc) · 2.6 KB

Comparison of ziplist, listpack and bidipack

Element encoding sizes

In the tables below, the total number of bytes is given for each range of values and each datastructure. For ziplists, this including prevlen, assuming the previous element is of the same size the current element.

In parentheses, the encoding nickname is given.

Integer range Ziplist Listpack Bidipack
0..12 2 (tiny) 2 1
0..127 3 2 (uint7) 1 (uint7)
-128..127 3 (int8) 3 3
-4096..4095 4 3 (int13) 3
-32K..32K 4 (int16) 4 (int16) 3 (int16)
-8M..8M 5 (int24) 5 (int24) 4 (int24)
-2G..2G 6 (int32) 6 (int32) 5 (int32)
-140T..140T 10 10 8 (int48)
-9E..9E 10 (int64) 10 (int64) 10 (int64)

Lengths of string encodings, excluding the string itself, are compared in the table below. For ziplists and listpacks, the notation (strN+M) means N bits for the string length and M bytes for the length-suffix or the prevlen field.

String length Ziplist Listpack Bidipack
the empty string 2 2 1 (str0)
up to 63 chars 2 (str6+1) 2 (str6+1) 2 (str6)
up to 127 chars 3 3 (str12+1) 4
up to 251 chars 3 (str14+1) 4 4
up to 4095 chars 7 4 (str12+2) 4 (str12)
up to 16383 chars 7 (str14+5) 7 (str32+2) 6
up to 65535 chars 10 8 6 (str16)
up to 2M chars 10 8 (str32+3) 10
up to 256M chars 10 9 (str32+4) 10
up to 4G chars 10 (str32+5) 10 (str32+5) 10 (str32)

Conclusions

The compact representation of integers in the range 0-127, which is half of that in the other encodings, is the major space saver. In scenarios where small integers are very common, bidipack can save up to 50% of the space.

Note that a string of length 64-127 requires one byte more in the bidipack representation than in the other two. The overhead is 3-6% of the string length, and the difference compared to the other representations (1 byte) is 0.7-1.5% of the string length. Also strings of length 65536-256M chars are longer in bidipack, but the overhead difference only 0.0003% for these. This is likely compensated by the more compact representation of small integers.