revlog: return lazy set from findcommonmissing
authorDurham Goode <durham@fb.com>
Mon, 11 Nov 2013 16:40:02 -0800
changeset 20073 eeba4eaf0716
parent 20072 6d4fda48b4e3
child 20074 5fc2ae1c631b
revlog: return lazy set from findcommonmissing When computing the commonmissing, it greedily computes the entire set immediately. On a large repo where the majority of history is irrelevant, this causes a significant slow down. Replacing it with a lazy set makes amend go from 11 seconds to 8.7 seconds.
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Nov 19 11:29:56 2013 -0500
+++ b/mercurial/revlog.py	Mon Nov 11 16:40:02 2013 -0800
@@ -401,7 +401,29 @@
         heads = [self.rev(n) for n in heads]
 
         # we want the ancestors, but inclusive
-        has = set(self.ancestors(common))
+        class lazyset(object):
+            def __init__(self, lazyvalues):
+                self.addedvalues = set()
+                self.lazyvalues = lazyvalues
+
+            def __contains__(self, value):
+                return value in self.addedvalues or value in self.lazyvalues
+
+            def __iter__(self):
+                added = self.addedvalues
+                for r in added:
+                    yield r
+                for r in self.lazyvalues:
+                    if not r in added:
+                        yield r
+
+            def add(self, value):
+                self.addedvalues.add(value)
+
+            def update(self, values):
+                self.addedvalues.update(values)
+
+        has = lazyset(self.ancestors(common))
         has.add(nullrev)
         has.update(common)