Redis › HyperLogLog in Redis
How does the internal sparse and dense representation of a HyperLogLog in Redis affect its memory usage as the number of unique items grows?
IntermediateAnswer
Redis initially stores a HyperLogLog using a compact sparse representation when the number of unique items is still small, automatically converting to a denser, slightly larger fixed size representation once the count of unique items grows beyond a certain threshold, balancing memory efficiency for smaller counts against the need for accuracy at larger scales.
-- Small HyperLogLogs use a more compact sparse encoding
-- automatically converting to dense encoding as they grow
STRLEN unique_visitors:today -- shows current memory footprintReal-world example A team monitoring memory usage notices a HyperLogLog's storage size grows slightly as more unique visitors are added throughout the day, understanding this is the expected transition from the sparse to dense internal representation.