[PATCH 11 of 13] perf: rely on repoview for perfbranchmapupdate

Boris Feld boris.feld at octobus.net
Fri Nov 23 09:09:07 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1542832522 0
#      Wed Nov 21 20:35:22 2018 +0000
# Node ID b0c7cead9b4e1c872b7bc8983a122cfb630045b6
# Parent  7db38417670e442bb34e0a047cfd6bed795a98f3
# EXP-Topic perf-branchmap
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b0c7cead9b4e
perf: rely on repoview for perfbranchmapupdate

Using 'repoview' matching the base and target subset make the benchmark more
realistic. It also unlocks optimization to make the command initialization
faster.

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -2199,8 +2199,10 @@ def perfbranchmapupdate(ui, repo, base=(
        $ hg perfbranchmapupdate --base 'stable' --target 'default'
     """
     from mercurial import branchmap
+    from mercurial import repoview
     opts = _byteskwargs(opts)
     timer, fm = gettimer(ui, opts)
+    unfi = repo.unfiltered()
     x = [None] # used to pass data between closure
 
     # we use a `list` here to avoid possible side effect from smartset
@@ -2223,21 +2225,43 @@ def perfbranchmapupdate(ui, repo, base=(
     newrevs = list(alltargetrevs.difference(allbaserevs))
     newrevs.sort()
 
+    allrevs = frozenset(unfi.changelog.revs())
+    basefilterrevs = frozenset(allrevs.difference(allbaserevs))
+    targetfilterrevs = frozenset(allrevs.difference(alltargetrevs))
+
+    def basefilter(repo, visibilityexceptions=None):
+        return basefilterrevs
+
+    def targetfilter(repo, visibilityexceptions=None):
+        return targetfilterrevs
+
     msg = 'benchmark of branchmap with %d revisions with %d new ones\n'
     ui.status(msg % (len(allbaserevs), len(newrevs)))
+    if targetfilterrevs:
+        msg = '(%d revisions still filtered)\n'
+        ui.status(msg % len(targetfilterrevs))
 
-    if True:
+    try:
+        repoview.filtertable['__perf_branchmap_update_base'] = basefilter
+        repoview.filtertable['__perf_branchmap_update_target'] = targetfilter
+
+        baserepo = repo.filtered('__perf_branchmap_update_base')
+        targetrepo = repo.filtered('__perf_branchmap_update_target')
+
         base = branchmap.branchcache()
-        base.update(repo, allbaserevs)
+        base.update(baserepo, allbaserevs)
 
         def setup():
             x[0] = base.copy()
 
         def bench():
-            x[0].update(repo, newrevs)
+            x[0].update(targetrepo, newrevs)
 
         timer(bench, setup=setup)
         fm.end()
+    finally:
+        repoview.filtertable.pop('__perf_branchmap_update_base', None)
+        repoview.filtertable.pop('__perf_branchmap_update_target', None)
 
 @command(b'perfbranchmapload', [
      (b'f', b'filter', b'', b'Specify repoview filter'),


More information about the Mercurial-devel mailing list