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

login
register
mail settings
Submitter Boris Feld
Date Sept. 13, 2018, 2:27 p.m.
Message ID <8b194b4eacc6b0ec1918.1536848873@localhost.localdomain>
Download mbox | patch
Permalink /patch/34605/
State Accepted
Headers show

Comments

Boris Feld - Sept. 13, 2018, 2:27 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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.
Augie Fackler - Sept. 13, 2018, 3:04 p.m.
> On Sep 13, 2018, at 10:27, Boris FELD <boris.feld@octobus.net> wrote:
> 
> # HG changeset patch
> # User Boris Feld <boris.feld@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)


queued, thanks

Patch

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)