revlog: filter out "invalid" delta base candidates
authorBoris Feld <boris.feld@octobus.net>
Fri, 27 Jul 2018 12:08:10 +0200
changeset 39087 f90b333e79cb
parent 39086 64ddad2f26bb
child 39088 ad88726d6982
revlog: filter out "invalid" delta base candidates There are bases that we know won't produce a good delta chain. For example, if the base is already bigger than twice the size of the text we store, we know the resulting delta chain will never be valid. We might make the check a bit more powerful and generic in the future, but this looks a good start. In particular, empty file (size 0) will never find a good base, so we should stop spending time trying to find one.
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Aug 14 13:47:07 2018 -0700
+++ b/mercurial/revlog.py	Fri Jul 27 12:08:10 2018 +0200
@@ -750,7 +750,11 @@
         deltaparent = self.revlog.deltaparent
 
         deltainfo = None
+        deltas_limit = revinfo.textlen * LIMIT_DELTA2TEXT
         for candidaterevs in self._getcandidaterevs(p1, p2, cachedelta):
+            # filter out delta base that will never produce good delta
+            candidaterevs = [r for r in candidaterevs
+                             if self.revlog.length(r) <= deltas_limit]
             nominateddeltas = []
             for candidaterev in candidaterevs:
                 # skip over empty delta (no need to include them in a chain)