Abstract
Run-Length Encoding (RLE) is a fundamental tool in data compression, yet its effectiveness is highly dependent on the presence of consecutive repeating elements. When data lacks these "runs," RLE can cause "size inflation," where the compressed output is larger than the original input. This paper presents a mathematical framework to quantify RLE's space savings based on input distribution. We introduce Selective RLE, an algorithm that automatically identifies and encodes only those symbols likely to yield savings. Experiments across tabular, time-series, and image datasets demonstrate that Selective RLE consistently avoids size inflation while maintaining the high efficiency of the original RLE algorithm.
Introduction: The Size Inflation Problem
Run-Length Encoding (RLE) is elegantly simple: instead of storing aaaaa, it stores the symbol a and the count 5. This works exceptionally well for repetitive data, such as sparse matrices or simple graphics. However, RLE suffers from a significant drawback known as size inflation.
Consider a sequence like abcde. A standard RLE encoder might represent this as <a, 1, b, 1, c, 1, d, 1, e, 1>. Because the encoder must store both the symbol and a "run-control" variable (the count), the output size doubles. Existing solutions often rely on slow "two-pass" scans or manual frequency thresholds that fail to generalize across different data modalities. This research seeks a robust, mathematical method to determine—on the fly—which symbols are suitable for compression.
Methodology: Combinatorial Analysis and Selective Encoding
Researchers from Huawei Galois Lab approached the problem by modeling the input as a sequence of Independently and Identically Distributed (i.i.d.) symbols. To derive an equation for expected space savings, they categorized runs into three distinct types: Head, Middle, and Tail.
The resulting Selective RLE algorithm operates in two stages:
-
Threshold Calculation: The complex combinatorial summations were simplified into a practical inequality. A symbol $x$ is deemed "suitable" for RLE if its probability $p_x$ meets the following condition: $$p_x \ge \frac{b_r}{b_x + b_r}$$ where $b_r$ is the bit-width of the run count and $b_x$ is the bit-width of the symbol.
-
Selective Encoding: The algorithm estimates symbol frequencies via sampling and builds a set of suitable symbols. During the encoding pass, RLE is applied only to these symbols; all others are stored in their raw format.
This approach maintains a time complexity of $O(N)$, ensuring the algorithm remains as computationally efficient as vanilla RLE.
Key Insights: Probability and Space Savings
The core insight of this work is that a symbol's suitability for RLE is not determined by its frequency alone, but by the ratio between its frequency and the overhead bits required for the run count.
As illustrated in the figure above, the expected space savings $R_x$ for a symbol $x$ eventually plateaus as the sequence length $N$ increases. Crucially, for symbols with low probabilities, the savings remain near zero or negative, confirming that RLE is counterproductive for infrequent symbols regardless of the total data volume. The derived threshold $\frac{b_r}{b_x + b_r}$ serves as a universal "go/no-go" signal to prevent these losses.
Experimental Evaluation
The authors tested Selective RLE against vanilla RLE (V-RLE) and common heuristics across three datasets:
- SO-2018 (Tabular): V-RLE frequently resulted in a Compression Ratio (CR) below 1.0. Selective RLE consistently maintained a CR $\ge$ 1.0.
- Netstream (Time-series): In these non-i.i.d. traffic logs, Selective RLE was the only method that never inflated the file size. V-RLE and heuristic methods (D-RLE) caused size inflation in 70% and 60% of cases, respectively.
- "Lena" (Image): V-RLE nearly doubled the image file size (from 128KB to 238KB). Selective RLE correctly identified that no symbols met the threshold, preserving the original file size and avoiding a "size explosion."
Conclusion
Selective RLE provides a mathematically grounded solution to the long-standing problem of size inflation in RLE. By filtering symbols through a simple, bit-width-based threshold, the algorithm ensures that compression never degrades storage efficiency. While the current theory assumes i.i.d. data, its empirical success on complex datasets suggests broad applicability. Future research will explore extending this framework to account for local dependencies and non-i.i.d. distributions.
Summary updated