Why doesn't support downgrade for intset?

26 views
Skip to first unread message

Jeffery

unread,
Sep 1, 2021, 6:51:40 AMSep 1
to Redis DB
After remove value, just need check the first and last value whether need downgrading.
This checking can run in O(1).
So who can tell me, why doesn't support downgrade for intset?

sundb

unread,
Sep 1, 2021, 10:54:14 PMSep 1
to Redis DB
You mean the downgrade from dict to intset?
Just the first and last are int doesn't mean the whole dict is integer.
And dict is not ordered, if we convert dict to intset, we also need to sort the entries of the dict.

Jeffery

unread,
Sep 2, 2021, 2:40:14 AMSep 2
to Redis DB
If adding some integer to a set, redis will store these integer with intset.
When i add a large integer to this set, intset would upgrade the intset's encoding to holding large integer automatically. The operation need more memory to holding whole integer data.
Now if i remove the largest integer, the intset is still used old large encoding, the intset is still used more memory to hoding whole integer data. The large encoding will result in wasted memory.

The integer data in intset is ordered.
So when removing data from intset, why not check the first and last value to using little encoding? It would save some memory.
I call it downgrade just due to the function name is intsetUpgradeAndAdd in source code(https://github.com/redis/redis/blob/unstable/src/intset.c#L158).

sundb

unread,
Sep 2, 2021, 4:49:12 AMSep 2
to Redis DB
But you need to consider that if an inset is added and deleted frequently if it can be downgraded, it will cause it to keep switching encoding, which will have a significant performance impact.
Reply all
Reply to author
Forward
0 new messages