Patchwork [3,of,5] revset: avoid in loop lookup in _generatorset._consumegen

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 19, 2014, 10:33 p.m.
Message ID <a2b305e889547516d795.1411166036@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5887/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 19, 2014, 10:33 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398902208 25200
#      Wed Apr 30 16:56:48 2014 -0700
# Node ID a2b305e889547516d7952ee8ecd67948cd8ff360
# Parent  a38a9240a0c57afe2f4939f41a63382ef76b92fc
revset: avoid in loop lookup in _generatorset._consumegen

Python lookup are slow, let do all lookup outside of the for loop.

This provide a small but still significant speedup:

revset #0: 0::
0) wall 0.063258 comb 0.060000 user 0.060000 sys 0.000000 (best of 100)
1) wall 0.057776 comb 0.050000 user 0.050000 sys 0.000000 (best of 100)
Augie Fackler - Sept. 24, 2014, 3:29 p.m.
On Fri, Sep 19, 2014 at 03:33:56PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1398902208 25200
> #      Wed Apr 30 16:56:48 2014 -0700
> # Node ID a2b305e889547516d7952ee8ecd67948cd8ff360
> # Parent  a38a9240a0c57afe2f4939f41a63382ef76b92fc
> revset: avoid in loop lookup in _generatorset._consumegen
>
> Python lookup are slow, let do all lookup outside of the for loop.

Queued first three. In 4 and 5, I think you mean "expensive" and not
"expensible".

>
> This provide a small but still significant speedup:
>
> revset #0: 0::
> 0) wall 0.063258 comb 0.060000 user 0.060000 sys 0.000000 (best of 100)
> 1) wall 0.057776 comb 0.050000 user 0.050000 sys 0.000000 (best of 100)
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2664,13 +2664,15 @@ class _generatorset(object):
>              else:
>                  yield consume.next()
>              i += 1
>
>      def _consumegen(self):
> +        cache = self._cache
> +        genlist = self._genlist.append
>          for item in self._gen:
> -            self._cache[item] = True
> -            self._genlist.append(item)
> +            cache[item] = True
> +            genlist(item)
>              yield item
>          self._finished = True
>
>      def set(self):
>          return self
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Sept. 24, 2014, 4:34 p.m.
On 09/24/2014 08:29 AM, Augie Fackler wrote:
> On Fri, Sep 19, 2014 at 03:33:56PM -0700, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@fb.com>
>> # Date 1398902208 25200
>> #      Wed Apr 30 16:56:48 2014 -0700
>> # Node ID a2b305e889547516d7952ee8ecd67948cd8ff360
>> # Parent  a38a9240a0c57afe2f4939f41a63382ef76b92fc
>> revset: avoid in loop lookup in _generatorset._consumegen
>>
>> Python lookup are slow, let do all lookup outside of the for loop.
>
> Queued first three. In 4 and 5, I think you mean "expensive" and not
> "expensible".

I do.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2664,13 +2664,15 @@  class _generatorset(object):
             else:
                 yield consume.next()
             i += 1
 
     def _consumegen(self):
+        cache = self._cache
+        genlist = self._genlist.append
         for item in self._gen:
-            self._cache[item] = True
-            self._genlist.append(item)
+            cache[item] = True
+            genlist(item)
             yield item
         self._finished = True
 
     def set(self):
         return self