git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Compression and dictionaries

From
Jon Smirl <jonsmirl@gmail.com>
Date
Aug 14, 2006, 14:08 UTC
Message-ID
<9e4733910608140708i45e3d6day6b87676783fd6511@mail.gmail.com>
In-Reply-To
<Pine.LNX.4.63.0608141415560.10541@wbgn013.biozentrum.uni-wuerzburg.de>
On 8/14/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 32 quoted lines
> Hi,
>
> On Sun, 13 Aug 2006, Jon Smirl wrote:
>
> > > From what I remember from long ago most compression schemes build
> > dictionaries as a way of achieving significant compression. If so,
> > since we zlib compress each entry in a pack individually, are there
> > many copies of very similar dictionaries in the pack?
>
> No, there are no dictionaries in the pack. At least no explicit ones.
>
> The trick is that the dictionary builds up with the data incrementally:
> both the encoding process and the decoding process construct it
> identically, on the fly.
>
> Example: A very primitive example of compression is the arithmetic coder
> of single characters. Given a probability distribution of the characters,
> each character is encoded such that the length of the encoding of one
> character is reciprocal to its probability *Footnote 1*. If you want to
> compress context-free, i.e. without looking at the characters before or
> after the current character when encoding or decoding, this is provably
> optimal.
>
> Now, if you do not have a probability distribution (because you haven't
> looked at the file yet), you can build an histogram as approximation on
> the fly. Whenever a character is encoded, you take the current histogram
> to approximate the probability distribution, and adjust the histogram for
> that character.
>
> For zlib, it is a little more involved (it is not a simple histogram), but
> the principle holds: if you do not have a dictionary, you just build one
> from the data seen so far.

Does a zlib dictionary just changes the probabilities in the histogram or does it turn the dictionary into a pre-loaded encoding tree?

The other compression schemes I looked at let you load in a precomputed huffman/arithmetic encoding tree. By preloading an encoding tree you avoid storing the encoding of "void => 010101' in every item. Removing 1M encoding maps and using one common one should be a win. Items not in the map would still be stored using internal additions to the map.

Changing the probabilities probably won't help much, but there may be good gains from partially eliminating 1M encoding maps.

Show 20 quoted lines
>
> BTW I doubt that an explicit dictionary would be good: Either you
> distribute it with git, and have many people complaining that it is either
> too small, or too big, and in most cases does not fit their data well, or
> you have to create it for each local repository, which takes time.
>
> Further, if the pack-file becomes corrupt, you usually still have the
> pack index, or the start of the pack-file, and can reconstruct most of the
> objects. If you use a dictionary, and just one bit flips in it, you're
> screwed.
>
> Ciao,
> Dscho
>
> Footnote 1: If the probabilities are all powers of two (with negative
> exponent), the encodings can be fixed bit strings (because the lengths are
> integer numbers); if that is not the case, it gets a little more
> complicated; basically, you store a fractional bit as a state; that is why
> it is called arithmetic coding.
>
-- 
Jon Smirl
jonsmirl@gmail.com
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 20 in “Compression and dictionaries”
  1. Jon SmirlAug 14, 2006
  2. Shawn PearceAug 14, 2006
  3. Jon SmirlAug 14, 2006
  4. Shawn PearceAug 14, 2006
  5. Alex RiesenAug 14, 2006
  6. Erik MouwAug 14, 2006
  7. Johannes SchindelinAug 14, 2006
  8. Jon SmirlAug 14, 2006
  9. Johannes SchindelinAug 14, 2006
  10. Jon SmirlAug 14, 2006
  11. David LangAug 14, 2006
  12. Jakub NarebskiAug 14, 2006
  13. Jeff GarzikAug 14, 2006
  14. David LangAug 14, 2006
  15. Jeff GarzikAug 14, 2006
  16. Jon SmirlAug 14, 2006
  17. David LangAug 14, 2006
  18. Johannes SchindelinAug 14, 2006
  19. Alex RiesenAug 14, 2006
  20. Johannes SchindelinAug 14, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.