Sketching and Streaming for Dictionary Compression

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

Abstract

Dictionary-based compression is essential for managing massive, repetitive datasets, yet estimating compression ratios typically requires significant memory and multiple passes. We introduce the first sub-linear space sketching and streaming algorithms to estimate the output size of such compressors by approximating normalized substring complexity ($\delta$). Our approach enables high-speed similarity comparisons, such as Normalized Compression Distance (NCD), using orders of magnitude less memory than traditional methods. We demonstrate the efficacy of our algorithms on a 189GB genomic dataset, which was processed using only 5MB of RAM.

Introduction

In the era of big data, determining the compressibility of a dataset before full processing is a critical task. While Shannon entropy ($H_0$) is easily estimated in a stream, it fails to capture the structure of highly repetitive data, such as genomic sequences or system logs, where dictionary-based compressors (e.g., LZ77, BWT) excel. Traditional dictionary compressors require substantial memory and often multiple passes to determine final output size. This makes calculating metrics like the Normalized Compression Distance (NCD)—which requires repeated pairwise compressions—prohibitively expensive for large-scale data.

Normalized Substring Complexity ($\delta$)

To address these challenges, we shift the focus from specific compressor outputs to a mathematically robust measure: normalized substring complexity ($\delta$). Defined as $\delta = \max_{k \ge 1} \{d_k / k\}$, where $d_k$ is the number of distinct substrings of length $k$, $\delta$ serves as a stable proxy for the information content of a string. Unlike specific compressor phrase counts, $\delta$ is monotone under concatenation and invariant under reversals, making it an ideal metric for similarity analysis.

Methods: Sketching and Streaming

Our core innovation is a data sketch with space complexity $O(\epsilon^{-3} \log n + \epsilon^{-1} \log^2 n)$. The sketch employs geometric sampling of substring lengths $k$ and utilizes count-distinct algorithms (similar to HyperLogLog) paired with Rabin fingerprints to estimate $d_k$ without storing the substrings themselves.

The streaming algorithm handles the challenge of calculating fingerprints for large $k$ values—which typically requires a large lookback window—through a hybrid approach. Small $k$ values are managed with a sliding window, while large $k$ values are handled by a Run-Length Burrows-Wheeler Transform (RLBWT).

Incremental construction of the BWT table during streaming, showing how suffixes and the BWT column are updated as new characters are processed.

The RLBWT remains compact if the data is highly repetitive. If the data lacks repetitiveness, large $k$ values do not significantly impact the maximum $\delta$, allowing them to be safely ignored. This keeps the total working space at $O(\sqrt{n} \log n)$.

Experimental Results

We evaluated our algorithms on several benchmarks, including the Pizza&Chilli Repetitive Corpus and a 189GB dataset of Rana muscosa genomic sequences.

Memory Efficiency and Throughput

The streaming algorithm demonstrated extreme memory efficiency, estimating the compressibility of the 189GB genomic dataset using only 5MB of RAM. It achieved a throughput of 203MB per minute on this high-volume data.

Similarity Comparison Performance

In phylogenetic tree reconstruction experiments, our sketching method computed all-pairs distances in just 3 minutes. In contrast, calculating exact $\delta$ took 24 minutes, and using the popular xz compressor required 42 minutes. Despite this speedup, the approximation $\tilde{\delta}$ remained within 5% of the true value.

Conclusion

By leveraging $\delta$ and efficient sketching techniques, we provide a scalable solution for estimating dictionary compression on massive streams. Our methods offer an exponential space improvement over previous nearly-linear time algorithms for random-access data and provide a practical tool for high-throughput genomic and log data analysis. Future work will focus on removing the requirement for a known upper bound on stream length and further optimizing the $\epsilon$ dependencies in space complexity.

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