Patchwork [3,of,4] revlog: change generaldelta delta parent heuristic

login
register
mail settings
Submitter Durham Goode
Date Aug. 30, 2015, 10:09 p.m.
Message ID <03338124de4c33848974.1440972594@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10330/
State Accepted
Headers show

Comments

Durham Goode - Aug. 30, 2015, 10:09 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1440968291 25200
#      Sun Aug 30 13:58:11 2015 -0700
# Node ID 03338124de4c33848974b5a512d4e6ef71b4424b
# Parent  a97c5320ea8b628ec619b0a5100507fe3ad585ed
revlog: change generaldelta delta parent heuristic

The old generaldelta heuristic was "if p1 (or p2) was closer than the last full text,
use it, otherwise use prev". This was problematic when a repo contained multiple
branches that were very different. If commits to branch A were pushed, and the
last full text was branch B, it would generate a fulltext. Then if branch B was
pushed, it would generate another fulltext. The problem is that the last
fulltext (and delta'ing against `prev` in general) has no correlation with the
contents of the incoming revision, and therefore will always have degenerate
cases.

According to the blame, that algorithm was chosen to minimize the chain length.
Since there is already code that protects against that (the delta-vs-fulltext
code), and since it has been improved since the original generaldelta algorithm
went in (2011), I believe the chain length criteria will still be preserved.

The new algorithm always diffs against p1 (or p2 if it's closer), unless the
resulting delta will fail the delta-vs-fulltext check, in which case we delta
against prev.

Some before and after stats on manifest.d size.

internal large repo
old heuristic - 2.0 GB
new heuristic - 1.2 GB

mozilla-central
old heuristic - 242 MB
new heuristic - 261 MB

The regression in mozilla central is due to the new heuristic choosing p2r as
the delta when it's closer to the tip. Switching the algorithm to always prefer
p1r brings the size back down (242 MB). This is result of the way in which
mozilla does merges and pushes, and the result could easily swing the other
direction in other repos (depending on if they merge X into Y or Y into X), but
will never be as degenerate as before.

I future patch will address the regression by introducing an optional, even more
aggressive delta heuristic which will knock the mozilla manifest size down
dramatically.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1343,11 +1343,14 @@  class revlog(object):
         # should we try to build a delta?
         if prev != nullrev:
             if self._generaldelta:
-                if p1r >= basecache[1]:
-                    d = builddelta(p1r)
-                elif p2r >= basecache[1]:
-                    d = builddelta(p2r)
-                else:
+                # Pick whichever parent is closer to us (to minimize the
+                # chance of having to build a fulltext). Since
+                # nullrev == -1, any non-merge commit will always pick p1r.
+                drev = p2r if p2r > p1r else p1r
+                d = builddelta(drev)
+                # If the chosen delta will result in us making a full text,
+                # give it one last try against prev.
+                if drev != prev and not self._isgooddelta(d, textlen):
                     d = builddelta(prev)
             else:
                 d = builddelta(prev)