changeset 20894:04e1596d5dbd

revset: improve _descendants performance Previously revset._descendants would iterate over the entire subset (which is often the entire repo) and test if each rev was in the descendants list. This is really slow on large repos (3+ seconds). Now we iterate over the descendants and test if they're in the subset. This affects advancing and retracting the phase boundary (3.5 seconds down to 0.8 seconds, which is even faster than it was in 2.9). Also affects commands that move the phase boundary (commit and rebase, presumably). The new revsetbenchmark indicates an improvement from 0.2 to 0.12 seconds. So future revset changes should be able to notice regressions. I removed a bad test. It was recently added and tested '1:: and reverse(all())', which has an amibiguous output direction. Previously it printed in reverse order, because we iterated over the subset (the reverse part). Now it prints in normal order because we iterate over the 1:: . Since the revset itself doesn't imply an order, I removed the test.
author Durham Goode <durham@fb.com>
date Tue, 25 Mar 2014 14:10:01 -0700
parents b5de9dde181c
children f52e4ca93529
files contrib/revsetbenchmarks.txt mercurial/revset.py tests/test-revset.t
diffstat 3 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/revsetbenchmarks.txt	Mon Mar 31 16:29:39 2014 -0700
+++ b/contrib/revsetbenchmarks.txt	Tue Mar 25 14:10:01 2014 -0700
@@ -12,4 +12,5 @@
 min(0:tip)
 0::
 min(0::)
+roots((tip~100::) - (tip~100::tip))
 ::p1(p1(tip))::
--- a/mercurial/revset.py	Mon Mar 31 16:29:39 2014 -0700
+++ b/mercurial/revset.py	Tue Mar 25 14:10:01 2014 -0700
@@ -661,8 +661,18 @@
     if not args:
         return baseset([])
     s = _revdescendants(repo, args, followfirst)
-    a = set(args)
-    return subset.filter(lambda r: r in s or r in a)
+
+    # Both sets need to be ascending in order to lazily return the union
+    # in the correct order.
+    args.ascending()
+
+    subsetset = subset.set()
+    result = (orderedlazyset(s, subsetset.__contains__, ascending=True) +
+              orderedlazyset(args, subsetset.__contains__, ascending=True))
+
+    # Wrap result in a lazyset since it's an _addset, which doesn't implement
+    # all the necessary functions to be consumed by callers.
+    return orderedlazyset(result, lambda r: True, ascending=True)
 
 def descendants(repo, subset, x):
     """``descendants(set)``
--- a/tests/test-revset.t	Mon Mar 31 16:29:39 2014 -0700
+++ b/tests/test-revset.t	Tue Mar 25 14:10:01 2014 -0700
@@ -474,16 +474,6 @@
   2
   1
   0
-  $ log '1:: and reverse(all())'
-  9
-  8
-  7
-  6
-  5
-  4
-  3
-  2
-  1
   $ log 'rev(5)'
   5
   $ log 'sort(limit(reverse(all()), 3))'