Patchwork [1,of,2] log: cache diffopts instance

login
register
mail settings
Submitter Yuya Nishihara
Date May 6, 2018, 2:41 a.m.
Message ID <5ab73949f3870cfaa4b1.1525574484@mimosa>
Download mbox | patch
Permalink /patch/31270/
State Accepted
Headers show

Comments

Yuya Nishihara - May 6, 2018, 2:41 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524984257 -32400
#      Sun Apr 29 15:44:17 2018 +0900
# Node ID 5ab73949f3870cfaa4b16180511f22a8f51130a8
# Parent  86e7a57449fa4f854d730cafd505ab089c25df76
log: cache diffopts instance

It appears that calling patch.diff*opts() repeatedly has some cost.

  $ hg log -T '{rev}\n' -R mercurial --time > /dev/null
  (orig) time: real 4.430 secs (user 4.370+0.000 sys 0.050+0.000)
  (new)  time: real 1.950 secs (user 1.880+0.000 sys 0.060+0.000)

'diffopts or {}' isn't necessary as patch.diff*opts() accepts opts=None.
Gregory Szorc - May 6, 2018, 4:17 a.m.
On Sat, May 5, 2018 at 7:41 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1524984257 -32400
> #      Sun Apr 29 15:44:17 2018 +0900
> # Node ID 5ab73949f3870cfaa4b16180511f22a8f51130a8
> # Parent  86e7a57449fa4f854d730cafd505ab089c25df76
> log: cache diffopts instance
>
> It appears that calling patch.diff*opts() repeatedly has some cost.
>
>   $ hg log -T '{rev}\n' -R mercurial --time > /dev/null
>   (orig) time: real 4.430 secs (user 4.370+0.000 sys 0.050+0.000)
>   (new)  time: real 1.950 secs (user 1.880+0.000 sys 0.060+0.000)
>
> 'diffopts or {}' isn't necessary as patch.diff*opts() accepts opts=None.
>

Queued, thanks.


>
> diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
> --- a/mercurial/logcmdutil.py
> +++ b/mercurial/logcmdutil.py
> @@ -154,6 +154,7 @@ class changesetprinter(object):
>          self.repo = repo
>          self.buffered = buffered
>          self._differ = differ or changesetdiffer()
> +        self._diffopts = patch.diffallopts(ui, diffopts)
>          self.diffopts = diffopts or {}
>          self.header = {}
>          self.hunk = {}
> @@ -300,13 +301,12 @@ class changesetprinter(object):
>      def _showpatch(self, ctx):
>          stat = self.diffopts.get('stat')
>          diff = self.diffopts.get('patch')
> -        diffopts = patch.diffallopts(self.ui, self.diffopts)
>          if stat:
> -            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
> +            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
>          if stat and diff:
>              self.ui.write("\n")
>          if diff:
> -            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
> +            self._differ.showdiff(self.ui, ctx, self._diffopts,
> stat=False)
>          if stat or diff:
>              self.ui.write("\n")
>
> @@ -316,6 +316,7 @@ class changesetformatter(changesetprinte
>      def __init__(self, ui, repo, fm, differ=None, diffopts=None,
>                   buffered=False):
>          changesetprinter.__init__(self, ui, repo, differ, diffopts,
> buffered)
> +        self._diffopts = patch.difffeatureopts(ui, diffopts, git=True)
>          self._fm = fm
>
>      def close(self):
> @@ -369,14 +370,13 @@ class changesetformatter(changesetprinte
>
>          stat = self.diffopts.get('stat')
>          diff = self.diffopts.get('patch')
> -        diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
>          if stat:
>              self.ui.pushbuffer()
> -            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
> +            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
>              fm.data(diffstat=self.ui.popbuffer())
>          if diff:
>              self.ui.pushbuffer()
> -            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
> +            self._differ.showdiff(self.ui, ctx, self._diffopts,
> stat=False)
>              fm.data(diff=self.ui.popbuffer())
>
>  class changesettemplater(changesetprinter):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -154,6 +154,7 @@  class changesetprinter(object):
         self.repo = repo
         self.buffered = buffered
         self._differ = differ or changesetdiffer()
+        self._diffopts = patch.diffallopts(ui, diffopts)
         self.diffopts = diffopts or {}
         self.header = {}
         self.hunk = {}
@@ -300,13 +301,12 @@  class changesetprinter(object):
     def _showpatch(self, ctx):
         stat = self.diffopts.get('stat')
         diff = self.diffopts.get('patch')
-        diffopts = patch.diffallopts(self.ui, self.diffopts)
         if stat:
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
         if stat and diff:
             self.ui.write("\n")
         if diff:
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
         if stat or diff:
             self.ui.write("\n")
 
@@ -316,6 +316,7 @@  class changesetformatter(changesetprinte
     def __init__(self, ui, repo, fm, differ=None, diffopts=None,
                  buffered=False):
         changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
+        self._diffopts = patch.difffeatureopts(ui, diffopts, git=True)
         self._fm = fm
 
     def close(self):
@@ -369,14 +370,13 @@  class changesetformatter(changesetprinte
 
         stat = self.diffopts.get('stat')
         diff = self.diffopts.get('patch')
-        diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
         if stat:
             self.ui.pushbuffer()
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
             fm.data(diffstat=self.ui.popbuffer())
         if diff:
             self.ui.pushbuffer()
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
             fm.data(diff=self.ui.popbuffer())
 
 class changesettemplater(changesetprinter):