delta-find: use a single snapshot cache when applying a group to an object
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 06 Nov 2022 17:53:17 -0500
changeset 49681 c261a628e525
parent 49680 40e24d82b513
child 49682 1e6c37360527
delta-find: use a single snapshot cache when applying a group to an object This will avoid walking the revlog over and over again in some situations. The difference is hard to show in our current benchmark suite, as the gain is lower than their overall instability.
mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py	Sun Nov 06 17:55:55 2022 -0500
+++ b/mercurial/revlogutils/deltas.py	Sun Nov 06 17:53:17 2022 -0500
@@ -664,6 +664,7 @@
     cachedelta,
     excluded_bases=None,
     target_rev=None,
+    snapshot_cache=None,
 ):
     """Provides group of revision to be tested as delta base
 
@@ -689,6 +690,7 @@
         p1,
         p2,
         cachedelta,
+        snapshot_cache=snapshot_cache,
     )
     while True:
         temptative = candidates.send(good)
@@ -799,7 +801,7 @@
     yield None
 
 
-def _refinedgroups(revlog, p1, p2, cachedelta):
+def _refinedgroups(revlog, p1, p2, cachedelta, snapshot_cache=None):
     good = None
     # First we try to reuse a the delta contained in the bundle.
     # (or from the source revlog)
@@ -819,8 +821,8 @@
                 debug_info['cached-delta.accepted'] += 1
             yield None
             return
-    # XXX cache me higher
-    snapshot_cache = SnapshotCache()
+    if snapshot_cache is None:
+        snapshot_cache = SnapshotCache()
     groups = _rawgroups(
         revlog,
         p1,
@@ -1053,6 +1055,7 @@
         self._write_debug = write_debug
         self._debug_search = debug_search
         self._debug_info = debug_info
+        self._snapshot_cache = SnapshotCache()
 
     def buildtext(self, revinfo, fh):
         """Builds a fulltext version of a revision
@@ -1265,6 +1268,7 @@
             cachedelta,
             excluded_bases,
             target_rev,
+            snapshot_cache=self._snapshot_cache,
         )
         candidaterevs = next(groups)
         while candidaterevs is not None: