revset: avoid in loop lookup in _generatorset._consumegen
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 30 Apr 2014 16:56:48 -0700
changeset 22528 b6dc3b79bb25
parent 22527 6e38b5d49977
child 22529 5c53d7888aef
revset: avoid in loop lookup in _generatorset._consumegen Python lookups are slow, so 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)
mercurial/revset.py
--- a/mercurial/revset.py	Fri Apr 25 14:51:24 2014 -0700
+++ b/mercurial/revset.py	Wed Apr 30 16:56:48 2014 -0700
@@ -2672,9 +2672,11 @@
             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