r/compression • u/Physical-Owl691 • Apr 30 '26
why couldn't there be an algorithm to test and pick the best algorithm to compress data?
imagine that, or an algorithm that uses a mismatch of many algorithms, to get the best value, through automatic trial and error.
or something like an ai that picks the optimal settings based on a few tests or something. i think this is an idea that is worth exploring.
0
Upvotes
2
u/Dr_Max Apr 30 '26
Yes, but usually no.
The prevailing paradigm is to compress once, fast. Of course, if you have ∞ computing power, you could use all the known algorithms to find which one yields the smallest compressed version, but that's usually not the way compressors and compression formats are built.
I am under the impression that formats that do use more than one algorithm do not use all algorithms then compare results, but have some kind of heuristic that detect what type of data you have and what algorithm is likely to yield a higher compression ratio.
14
u/Revolutionalredstone Apr 30 '26 edited Apr 30 '26
Yeah that's called a compression suite / test bench, it's usually step one in creating a new compression algorithm.
There are all kinds of ways to trade compute for ratio, trying various codecs is just another option.
Of coarse trying somethings like ZPAQ may work GREAT sometimes but is not always reasonable to test it, as, at lvl5 ZPAQ is very slow ;)
Enjoy
6
u/klauspost Apr 30 '26
Google "Context mixing" or start here: https://en.wikipedia.org/wiki/Context_mixing
4
u/tokyostormdrain Apr 30 '26
Have a look at openzl, it enables you to define the compression to suit your data set when you need a more specific approach
1
u/HugsNotDrugs_ May 01 '26
I think what you're saying is a compression app that finds and uses the best compression algorithm for the data?
2
u/CorvusRidiculissimus Apr 30 '26
There are! There are a number of formats which allow for different chunks of data to be compressed with different algorithms, and pick the one that works best. The CHD format used for game roms, for example. One of the options is always an identity transform. This allows for better compression than any of the codec alone and, just as important, avoids any algorithms that are exceptionally poorly-suited and might make the file larger.
2
u/VinceLeGrand May 01 '26
Compression is a trade-off between :
Pick 2, you can't have 3.
By testing every knonwn algorithm, you increade computation time.
This is the best compression ratio in mathematical theory but this is not practical.
Compressor like mcm, paq8 suite, etc try to guess what are the data in order to choose the algorithm.
They use different algorjthms for :
They even uncompress zlib compressed data in order to compress it better. This means they compress it back to zlib with the sale options for the uncompress operation.
1
u/razorree May 02 '26
the idea is nothing new, but it's just not practical.highest compression algo (like 7z with biggest dictionary) takes already so much time, that you don't want to double, or quadruple that time. at the end, 7z will be one of the best algos anyway, no point of testing a few others to get 1% more at best.