Sketching and Streaming for Dictionary Compression

Ruben Becker, Matteo Canton, Davide Cenzato, Sung-Hwan Kim, Bojana Kodric, Nicola Prezza

TL;DR

This paper introduces the first sub-linear space sketching and streaming algorithms designed to estimate the output size of dictionary-based compressors (like Gzip or 7-Zip) on massive datasets. By approximating "normalized substring complexity" ($\delta$), the authors enable high-speed similarity comparisons and compressibility estimates for repetitive data (like genomes) using orders of magnitude less memory than traditional methods.

What Problem Does This Paper Address?

In the era of big data, we often need to know how "compressible" a dataset is before we actually process it. Traditional measures like Shannon entropy ($H_0$) are easy to estimate in a stream but fail miserably on highly repetitive data—such as genomic sequences or system logs—where dictionary compressors (LZ77, BWT, grammar-based) excel.

However, dictionary compressors typically require significant memory and multiple passes over the data to determine their final output size. Calculating the Normalized Compression Distance (NCD)—a powerful tool for measuring similarity between two strings—is particularly expensive because it requires compressing pairs of strings repeatedly. The gap addressed here is the lack of "sketches" (compact summaries) that can estimate these complex compression measures in a single pass (streaming) using very little memory (sub-linear space).

Methods

The authors shift the focus from specific compressor outputs (like the number of LZ77 phrases) to a more mathematically robust measure called normalized substring complexity ($\delta$). $\delta$ is defined as the maximum ratio of distinct substrings of length $k$ to $k$ itself ($\delta = \max_{k \ge 1} \{d_k / k\}$).

The Sketch

The core innovation is a data sketch that uses $O(\epsilon^{-3} \log n + \epsilon^{-1} \log^2 n)$ words of space.

  1. Geometric Sampling: Instead of checking every possible substring length $k$, they sample $k$ at geometric intervals (e.g., $k = 1, (1+\epsilon), (1+\epsilon)^2, \dots$).
  2. Count-Distinct Sketches: For each sampled $k$, they use a count-distinct algorithm (similar to HyperLogLog) to estimate the number of unique length-$k$ substrings.
  3. Rabin Fingerprints: To avoid storing the substrings themselves, they use rolling hashes (Rabin fingerprints) which allow for fast updates.

The Streaming Algorithm

Streaming is difficult because calculating a length-$k$ fingerprint usually requires looking back $k$ characters. If $k$ is large, you’d normally need to store the whole string. The authors solve this with a clever hybrid approach:

  • Small $k$: Stored in a simple sliding window.
  • Large $k$: Handled by a Run-Length Burrows-Wheeler Transform (RLBWT). If the data is repetitive enough that large $k$ values matter, the RLBWT remains very small. If the data isn't repetitive, large $k$ values don't affect the maximum, so they can be ignored. This keeps the working space at $O(\sqrt{n} \log n)$.

Datasets

The researchers evaluated their algorithms on several benchmark collections:

  • Pizza&Chilli Repetitive Corpus: A standard set for testing compression on repetitive data (DNA, source code, etc.).
  • Large Canterbury Corpus: A classic compression benchmark.
  • AF Project (Gene-trees): Used for the phylogenetic tree reconstruction experiments.
  • Rana Muscosa (Frog) Genomic Data: A massive 189GB dataset of long-read sequences used to test high-throughput streaming.

Key Insights and Ideas

  • $\delta$ as a "Better" Measure: Unlike specific compressor outputs, $\delta$ is monotone under concatenation and invariant under reversals. This makes it a more stable "proxy" for the true information content of a string.
  • The Power of Merging: Because the sketches are based on count-distinct structures, the sketches of two different strings ($S_1$ and $S_2$) can be merged to estimate the complexity of their union. This is the "secret sauce" for speeding up NCD calculations.
  • Exponential Space Improvement: For random-access data, this algorithm provides a polylogarithmic space solution, an exponential improvement over previous nearly-linear time algorithms.

Key Results

  • Extreme Memory Efficiency: The streaming algorithm estimated the compressibility of a 189GB dataset using only 5MB of RAM.
  • High Throughput: The implementation achieved a throughput of 203MB per minute on the large genomic dataset.
  • Massive Speedup for NCD: When reconstructing phylogenetic trees (evolutionary relationships), the sketching method computed all-pairs distances in 3 minutes, compared to 24 minutes for exact $\delta$ and 42 minutes for the popular xz compressor.
  • Accuracy: The approximation $\tilde{\delta}$ stayed within 5% of the true value even with sparse sampling.

Limitations and Future Work

  • Prior Knowledge: The streaming algorithm currently requires an upper bound on the total stream length ($n$) to be known in advance to set parameters.
  • Space Complexity: While the sketch itself is polylogarithmic, the streaming algorithm's working space is $O(\sqrt{n} \log n)$. While sub-linear, it is still larger than a pure sketch.
  • Worst-Case Delay: While the average performance is excellent, the authors note a worst-case delay per character that depends on $\epsilon^{-1} \log^2 n$.
  • Future Directions: The authors suggest exploring whether the requirement for a known $n$ can be removed and if the $\epsilon$ dependencies in the space complexity can be further optimized.

Summary updated

BibTeX
@inproceedings{becker2024sketching,
  author = {Ruben Becker and Matteo Canton and Davide Cenzato and Sung-Hwan Kim and Bojana Kodric and Nicola Prezza},
  title = {{Sketching and Streaming for Dictionary Compression}},
  booktitle = {DCC},
  year = {2024},
  doi = {10.1109/dcc58796.2024.00029},
}
Figure