Patchwork [5,of,6] perftemplating: stop going through the log command

login
register
mail settings
Submitter Boris Feld
Date June 11, 2018, 7:52 a.m.
Message ID <d3a7e385f495769fc0bd.1528703544@localhost.localdomain>
Download mbox | patch
Permalink /patch/32053/
State Accepted
Headers show

Comments

Boris Feld - June 11, 2018, 7:52 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1527787384 -7200
#      Thu May 31 19:23:04 2018 +0200
# Node ID d3a7e385f495769fc0bdd37a0801dfb7ee7f153d
# Parent  a8dd8972d7b4e809dd9533af7e977ad686b6220c
# EXP-Topic perftemplate
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r d3a7e385f495
perftemplating: stop going through the log command

Only benchmark the rendering phase by moving steps outside of the timed
function:

* revisions resolution,
* template parsing
Yuya Nishihara - June 11, 2018, 11:50 a.m.
On Mon, 11 Jun 2018 09:52:24 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1527787384 -7200
> #      Thu May 31 19:23:04 2018 +0200
> # Node ID d3a7e385f495769fc0bdd37a0801dfb7ee7f153d
> # Parent  a8dd8972d7b4e809dd9533af7e977ad686b6220c
> # EXP-Topic perftemplate
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r d3a7e385f495
> perftemplating: stop going through the log command

Queued the series, thanks.

> +try:
> +    from mercurial import logcmdutil
> +    makelogtemplater = logcmdutil.maketemplater
> +except (AttributeError, ImportError):
> +    try:
> +        from mercurial import cmdutil

Removed this line since cmdutil is imported at top.

>  def perftemplating(ui, repo, **opts):
> +    if makelogtemplater is None:
> +        ui.write_err('incompatible Mercurial version')
> +        return 1

Nit: the other perf commands do abort instead of returning 1.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -81,6 +81,16 @@  except (AttributeError, ImportError):
     except (AttributeError, ImportError):
         queue = util.queue
 
+try:
+    from mercurial import logcmdutil
+    makelogtemplater = logcmdutil.maketemplater
+except (AttributeError, ImportError):
+    try:
+        from mercurial import cmdutil
+        makelogtemplater = cmdutil.makelogtemplater
+    except (AttributeError, ImportError):
+        makelogtemplater = None
+
 # for "historical portability":
 # define util.safehasattr forcibly, because util.safehasattr has been
 # available since 1.9.3 (or 94b200a11cf7)
@@ -901,14 +911,26 @@  def perfmoonwalk(ui, repo, **opts):
          [('r', 'rev', [], 'revisions to run the template on'),
          ] + formatteropts)
 def perftemplating(ui, repo, **opts):
+    if makelogtemplater is None:
+        ui.write_err('incompatible Mercurial version')
+        return 1
+
     nullui = ui.copy()
     nullui.fout = open(os.devnull, 'wb')
     nullui.disablepager()
     revs = opts.get('rev')
+    if not revs:
+        revs = ['all()']
+    revs = list(scmutil.revrange(repo, revs))
+
+    template = ('{date|shortdate} [{rev}:{node|short}]'
+                ' {author|person}: {desc|firstline}\n')
+    displayer = makelogtemplater(nullui, repo, template)
     def format():
-        commands.log(nullui, repo, rev=revs, date='', user='',
-                     template='{date|shortdate} [{rev}:{node|short}]'
-                              ' {author|person}: {desc|firstline}\n')
+        for r in revs:
+            ctx = repo[r]
+            displayer.show(ctx)
+            displayer.flush(ctx)
 
     timer, fm = gettimer(ui, opts)
     timer(format)