[PATCH STABLE] commit: increase perf by avoiding unnecessary filteredrevs check

Durham Goode durham at fb.com
Fri Nov 16 23:40:33 UTC 2012


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1353109152 28800
# Node ID 270338011eff9c88433e9cced0ba4a1c424b3d4a
# Parent  adca8ebf288c9ed00166298f3be192747d889b82
commit: increase perf by avoiding unnecessary filteredrevs check

When commiting to a repo with lots of history (>400000 changesets)
the filteredrevs check (added with 5c89e7fa5bc2) in changelog.py
takes a bit of time even if the filteredrevs set is empty. Skipping
the check in that case shaves 0.36 seconds off a 2.14 second commit.
A 17% gain.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -134,9 +134,15 @@
 
     def __iter__(self):
         """filtered version of revlog.__iter__"""
-        for i in xrange(len(self)):
-            if i not in self.filteredrevs:
-                yield i
+        if len(self.filteredrevs) == 0:
+            return revlog.revlog.__iter__(self)
+
+        def filterediter():
+            for i in xrange(len(self)):
+                if i not in self.filteredrevs:
+                    yield i
+
+        return filterediter()
 
     def revs(self, start=0, stop=None):
         """filtered version of revlog.revs"""
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -254,8 +254,7 @@
     def __len__(self):
         return len(self.index) - 1
     def __iter__(self):
-        for i in xrange(len(self)):
-            yield i
+        return iter(xrange(len(self)))
     def revs(self, start=0, stop=None):
         """iterate over all rev in this revlog (from start to stop)"""
         if stop is None:



More information about the Mercurial-devel mailing list