Abstract
HyperLogLogLog (HLLL) is a practical, lossless compression of the industry-standard HyperLogLog sketch that reduces memory usage by approximately 40% without sacrificing accuracy or mergeability. By storing register values as small 3-bit offsets from a dynamically shifting base value, HLLL approaches theoretical entropy bounds while remaining a drop-in replacement for existing big data systems.
Introduction
Cardinality estimation—counting the number of unique elements in a massive data stream—is a fundamental task in computer science, used for everything from detecting network intrusions to analyzing unique search queries. Storing every unique element is impossible at scale, so researchers use "sketches": compact data structures that provide an estimate with a small margin of error.
The current gold standard is HyperLogLog (HLL). While HLL is very efficient, it isn't mathematically optimal. It uses $O(m \log \log n)$ bits, where $m$ is the number of registers and $n$ is the cardinality. Theoretical "optimal" algorithms exist, but they are often too complex to implement, slow to update, or "non-mergeable." The authors of this paper sought a "sweet spot": a practical algorithm that is significantly smaller than HLL but just as fast and flexible.
Methodology: The Base + Offset Approach
The core insight of HyperLogLogLog is that in a standard HLL sketch, most register values cluster tightly around a predictable "fat region" centered at $\log_2(n/m)$. Instead of storing full values in every register, HLLL uses a Base + Offset approach:
- Base Value ($B$): A single value representing the current "floor" of the registers.
- Dense Array: A fixed-size array where each register stores a tiny offset (3 bits) relative to the base.
- Sparse Map: An associative array that stores "outliers"—values that are either too small or too large to fit in the 3-bit offset range.
As the cardinality $n$ grows, the registers' values naturally increase. The algorithm periodically performs a "rebase" operation, shifting the base value $B$ upward and moving registers between the dense array and the sparse map to keep the representation optimal. Crucially, this compression is lossless; an HLLL sketch can be converted back into a standard HLL sketch at any time.
Implementation and Evaluation
The authors evaluated HLLL against several industry-standard implementations using synthetic datasets including random 64-bit integers and ASCII strings. The comparison included variants of HLL from Apache DataSketches and Google's ZetaSketch.
Key Insights
- The "One Log More" Advantage: HLLL reduces space complexity by another logarithmic factor ($m \log \log \log n$) compared to HLL.
- Amortized Efficiency: While rebasing is an $O(m)$ operation, it happens exponentially less often as $n$ grows, leading to amortized constant time updates.
- Mergeability: HLLL sketches can be merged in the compressed domain, which is essential for distributed frameworks like MapReduce or Spark.
- Optimality: Using just 3 bits for dense offsets allows the sketch to capture the vast majority of values, nearing the theoretical entropy limit of ~2.8 bits per register.
Results and Conclusion
HLLL achieves a ~40% reduction in sketch size compared to standard HLL implementations. For large cardinalities, HLLL is nearly as fast as vanilla HLL. An optimized variant, HLLL*, uses heuristics to trigger rebasing more efficiently, making it highly competitive with Google's ZetaSketch.
Because HLLL produces the exact same estimates as HLL, it serves as a drop-in replacement that can be integrated into existing systems without changing statistical logic. Future work may explore the use of succinct dictionaries for the sparse component to further minimize space overhead for small cardinalities.
Summary updated