[PATCH STABLE] spanset: directly use __contains__ instead of a lambda

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Wed Apr 30 18:10:40 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1398497882 25200
#      Sat Apr 26 00:38:02 2014 -0700
# Branch stable
# Node ID cc12dff4f19ca264a4916709f9328d8ddc2eab48
# Parent  e2031c8ca4f8939a21fea454cb64b7a2744d9c8d
spanset: directly use __contains__ instead of a lambda

Spanset are massively used in revset. First because the initial subset itself is
a repo wide spanset. We speed up the __and__ operation by getting rid of a
gratuitous lambda call. A more long terms solution would be to:

1. speed up operation between spansets,
2. have a special smartset for `all` revisions.

In the mean time, this is a very simple fix that buyback some of the performance
regression.

Below is performance benchmark for trival `and` operation between two spansets.
(Run on an unspecified fairly large repository.)

revset tip:0
2.9.2)  wall 0.282543 comb 0.280000 user 0.260000 sys 0.020000 (best of 35)
before) wall 0.819181 comb 0.820000 user 0.820000 sys 0.000000 (best of 12)
after)  wall 0.645358 comb 0.650000 user 0.650000 sys 0.000000 (best of 16)

Proof of concept implementation of an `all` smartset brings this to 0.10 but it's
too invasive for stable.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2795,13 +2795,13 @@ class spanset(_orderedsetmixin):
 
     def __and__(self, x):
         if isinstance(x, baseset):
             x = x.set()
         if self._start <= self._end:
-            return orderedlazyset(self, lambda r: r in x)
+            return orderedlazyset(self, x.__contains__)
         else:
-            return orderedlazyset(self, lambda r: r in x, ascending=False)
+            return orderedlazyset(self, x.__contains__, ascending=False)
 
     def __sub__(self, x):
         if isinstance(x, baseset):
             x = x.set()
         if self._start <= self._end:


More information about the Mercurial-devel mailing list