[PATCH 2 of 2 FOLLOW-UP] revlog: reuse cached delta for identical base revision (issue5975)

Boris Feld boris.feld at octobus.net
Thu Sep 13 10:27:53 EDT 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1536561101 -7200
#      Mon Sep 10 08:31:41 2018 +0200
# Node ID 8b194b4eacc6b0ec191863c1385ec47124939fce
# Parent  bf9d5d5513d0babd5e1d59df1c1fa26c244faae5
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 8b194b4eacc6
revlog: reuse cached delta for identical base revision (issue5975)

Since 8f83a953dddf, we skip over empty deltas when choosing a delta base. Such
delta happens when two distinct revisions have the same content.

The remote might be sending a delta against such revision within the bundle.
In that case, the delta base is no longer considered, but the cached one could
still, be used with the equivalent revision.

Not reusing the delta from the bundle can have a significant performance
impact, so we now make sure with doing so when possible.

diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -832,9 +832,18 @@ class deltacomputer(object):
 
     def _builddeltainfo(self, revinfo, base, fh):
         # can we use the cached delta?
-        if revinfo.cachedelta and revinfo.cachedelta[0] == base:
-            delta = revinfo.cachedelta[1]
-        else:
+        delta = None
+        if revinfo.cachedelta:
+            cachebase, cachediff = revinfo.cachedelta
+            #check if the diff still apply
+            currentbase = cachebase
+            while (currentbase != nullrev
+                    and currentbase != base
+                    and self.revlog.length(currentbase) == 0):
+                currentbase = self.revlog.deltaparent(currentbase)
+            if currentbase == base:
+                delta = revinfo.cachedelta[1]
+        if delta is None:
             delta = self._builddeltadiff(base, revinfo, fh)
         revlog = self.revlog
         header, data = revlog.compress(delta)


More information about the Mercurial-devel mailing list