Back to results for “Redis Memory Optimization”
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?

Intermediate

Answer

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 footprint
Real-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.

Common follow-ups: At what point does Redis switch from sparse to dense representation?;Does this internal representation change affect how you interact with the HyperLogLog commands?