Mercurial > hg-stable
diff mercurial/revlog.py @ 30792:4215dc1b708b
revlog: make compressed size comparisons consistent
revlog.compress() compares the compressed size to the input size
and throws away the compressed data if it is larger than the input.
This is the correct thing to do, as storing compressed data that
is larger than the input takes up more storage space and makes reading
slower.
However, the comparison was implemented inconsistently. For the
streaming compression mode, we threw away the result if it was
greater than or equal to the input size. But for the one-shot
compression, we threw away the compression only if it was greater
than the input size!
This patch changes the comparison for the simple case so it is
consistent with the streaming case.
As a few tests demonstrate, this adds 1 byte to some revlog entries.
This is because of an added 'u' header on the chunk. It seems
somewhat wrong to increase the revlog size here. However, IMO the cost
of 1 byte in storage is insignificant compared to the performance gains
of avoiding decompression. This patch should invite questions around
the heuristic for throwing away compressed data. For example, I'd argue
we should be more liberal about rejecting compressed data, additionally
doing so where the number of bytes saved fails to reach a threshold.
But we can have this discussion another time.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 02 Jan 2017 11:50:17 -0800 |
parents | 1c7368d1a25f |
children | b6f455a6e4d6 |
line wrap: on
line diff
--- a/mercurial/revlog.py Sat Jan 07 20:43:49 2017 -0800 +++ b/mercurial/revlog.py Mon Jan 02 11:50:17 2017 -0800 @@ -1503,7 +1503,7 @@ bin = "".join(p) else: bin = _compress(text) - if bin is None or len(bin) > l: + if bin is None or len(bin) >= l: if text[0] == '\0': return ("", text) return ('u', text)