changeset 2223:2ba541e1ea01

stablerange: add warming of the subrange Note that this means we build standard stable subrange for all changesets in the repository this is significantly more than what we were computing before and result is significantly more ranges being computed.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 24 Mar 2017 03:20:29 +0100
parents 6b19998242ed
children 49776d324d1a
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Fri Mar 24 11:04:38 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Fri Mar 24 03:20:29 2017 +0100
@@ -8,6 +8,7 @@
 # GNU General Public License version 2 or any later version.
 
 import collections
+import heapq
 import math
 
 from mercurial import (
@@ -181,8 +182,44 @@
     def warmup(self, repo, heads):
         """warm the cache up to 'heads'"""
         repo = repo.unfiltered()
-        for r in repo.revs("::%ld", heads):
+        # subrange should be warmed from head to range to be able to benefit
+        # from revsfromrange cache. otherwise each merge will trigger its own
+        # stablesort.
+        #
+        # we use the revnumber as an approximation for depth
+        ui = repo.ui
+
+        revs = repo.revs("::%ld", heads)
+        nbrevs = len(revs)
+        rangeheap = []
+        for idx, r in enumerate(revs):
+            if not idx % 1000:
+                ui.progress(_("filling depth cache"), idx, total=nbrevs)
+            # warm up depth
             self.depthrev(repo, r)
+            rangeheap.append((-r, (r, 0)))
+        ui.progress(_("filling depth cache"), None, total=nbrevs)
+
+        heappop = heapq.heappop
+        heappush = heapq.heappush
+        heapify = heapq.heapify
+
+        original = set(rangeheap)
+        seen = 0
+        heapify(rangeheap)
+        while rangeheap:
+            value = heappop(rangeheap)
+            if value in original:
+                if not seen % 1000:
+                    ui.progress(_("filling stablerange cache"), seen, total=nbrevs)
+                seen += 1
+                original.remove(value) # might have been added from other source
+            __, rangeid = value
+            if self._subrangescache.get(rangeid) is None:
+                for sub in self.subranges(repo, rangeid):
+                    if self._subrangescache.get(sub) is None:
+                        heappush(rangeheap, (-sub[0], sub))
+        ui.progress(_("filling stablerange cache"), None, total=nbrevs)
 
     def depthrev(self, repo, rev):
         repo = repo.unfiltered()