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

login
register
mail settings
Submitter Boris Feld
Date Nov. 23, 2018, 2:09 p.m.
Message ID <b0c7cead9b4e1c872b7b.1542982147@localhost.localdomain>
Download mbox | patch
Permalink /patch/36740/
State Accepted
Headers show

Comments

Boris Feld - Nov. 23, 2018, 2:09 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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.

Patch

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'),