snapshot: introduce an intermediate `_refinedgroups` generator
authorBoris Feld <boris.feld@octobus.net>
Fri, 07 Sep 2018 11:17:32 -0400
changeset 39496 2f9f7889549b
parent 39495 6a53842727c1
child 39497 5b308a4e6d03
snapshot: introduce an intermediate `_refinedgroups` generator This method will be used to improve the search for a good snapshot base. To keep things simpler, we introduce the necessary function before doing any delta base logic change. The next handful of commits will focus on refactoring the code to let that new logic land as clearly as possible. # General Idea Right now, the search for a good delta base stop whenever we found a good one. However, when using sparse-revlog, we should probably try a bit harder. We do significant effort to increase delta re-use by jumping on "unrelated" delta chains that provide better results. Moving to another chain for a better result is good, but we have no guarantee we jump at a reasonable point in that new chain. When we consider over the chains related to the parents, we start from the higher-level snapshots. This is a way to consider the snapshot closer to the current revision that has the best chance to produce a small delta. We do benefit from this walk order when jumping to a better "unrelated" stack. To counter-balance this, we'll introduce a way to "refine" the result. After a good delta have been found, we'll keep searching for a better delta, using the current best one as a starting point. # Target Setup The `finddeltainfo` method is responsible for the general search for a good delta. It requests candidates base from `_candidategroups` and decides which one are usable. The `_candidategroups` generator act as a top-level filter, it does not care about how we pick candidates, it just does basic filtering, excluding revisions that have been tested already or that are an obvious misfit. The `_rawgroups` generator is the one with the actual ancestors walking logic, It does not care about what would do a good delta and what was already tested, it just issues the initial candidates. We introduce a new `_refinedgroup` function to bridge the gap between `_candidategroups` and `_rawgroups`. It delegates the initial iteration logic and then performing relevant refining of the valid base once found. (This logic is yet to be added to function) All these logics are fairly independent and easier to understand when standing alone, not mixed with each other. It also makes it easy to test and try different approaches for one of those four layers without affecting the other ones. # Technical details To communicate `finddeltainfo` choice of "current best delta base" to the `_refinegroup` logic, we plan to use python co-routine feature. The `_candidategroups` and `_refinegroup` generators will become co-routine. This will allow `_refinegroup` to detect when a good delta have been found and triggers various refining steps. For now, `_candidategroups` will just pass the value down the stack. After poking at various option, the co-routine appears the best to keep each layers focus on its duty, without the need to spread implementation details across layers.
mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py	Fri Sep 07 11:17:31 2018 -0400
+++ b/mercurial/revlogutils/deltas.py	Fri Sep 07 11:17:32 2018 -0400
@@ -585,7 +585,7 @@
     deltas_limit = textlen * LIMIT_DELTA2TEXT
 
     tested = set([nullrev])
-    for temptative in _rawgroups(revlog, p1, p2, cachedelta):
+    for temptative in _refinedgroups(revlog, p1, p2, cachedelta):
         group = []
         for rev in temptative:
             # skip over empty delta (no need to include them in a chain)
@@ -621,6 +621,13 @@
         if issnapshot(rev):
             cache[deltaparent(rev)].append(rev)
 
+def _refinedgroups(revlog, p1, p2, cachedelta):
+    good = None
+    for candidates in _rawgroups(revlog, p1, p2, cachedelta):
+        good = yield candidates
+        if good is not None:
+            break
+
 def _rawgroups(revlog, p1, p2, cachedelta):
     """Provides group of revision to be tested as delta base