perf: add a `--clear-caches` to `perfbranchmapupdate`
authorBoris Feld <boris.feld@octobus.net>
Fri, 23 Nov 2018 01:09:37 +0100
changeset 40772 5cbb74999040
parent 40771 58355a1de6b3
child 40773 0605726179a0
perf: add a `--clear-caches` to `perfbranchmapupdate` This flag will help to measure the time we spend loading various cache that support the branchmap update. Example for an 500 000 revisions repository: hg perfbranchmapupdate --base 'not tip' --target 'tip' ! wall 0.000860 comb 0.000000 user 0.000000 sys 0.000000 (best of 336) hg perfbranchmapupdate --base 'not tip' --target 'tip' --clear-caches ! wall 0.029494 comb 0.030000 user 0.030000 sys 0.000000 (best of 100)
contrib/perf.py
--- a/contrib/perf.py	Wed Nov 21 21:11:47 2018 +0000
+++ b/contrib/perf.py	Fri Nov 23 01:09:37 2018 +0100
@@ -2285,10 +2285,16 @@
 @command(b'perfbranchmapupdate', [
      (b'', b'base', [], b'subset of revision to start from'),
      (b'', b'target', [], b'subset of revision to end with'),
+     (b'', b'clear-caches', False, b'clear cache between each runs')
     ] + formatteropts)
 def perfbranchmapupdate(ui, repo, base=(), target=(), **opts):
     """benchmark branchmap update from for <base> revs to <target> revs
 
+    If `--clear-caches` is passed, the following items will be reset before
+    each update:
+        * the changelog instance and associated indexes
+        * the rev-branch-cache instance
+
     Examples:
 
        # update for the one last revision
@@ -2301,6 +2307,7 @@
     from mercurial import repoview
     opts = _byteskwargs(opts)
     timer, fm = gettimer(ui, opts)
+    clearcaches = opts[b'clear_caches']
     unfi = repo.unfiltered()
     x = [None] # used to pass data between closure
 
@@ -2366,6 +2373,9 @@
 
         def setup():
             x[0] = base.copy()
+            if clearcaches:
+                unfi._revbranchcache = None
+                clearchangelog(repo)
 
         def bench():
             x[0].update(targetrepo, newrevs)