Patchwork [6,of,8,STABLE] revset: inline spanset containment check (fix perf regression)

login
register
mail settings
Submitter Pierre-Yves David
Date April 29, 2014, 12:48 a.m.
Message ID <881523ca83343eb7e613.1398732513@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4450/
State Accepted
Commit 1d7a2771aa36e00770dc6c13def7371b637b5736
Headers show

Comments

Pierre-Yves David - April 29, 2014, 12:48 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398723336 25200
#      Mon Apr 28 15:15:36 2014 -0700
# Branch stable
# Node ID 881523ca83343eb7e613cb254b46195b8a3261c0
# Parent  ecb408545af84321d08594bb5deebbafb0df11b8
revset: inline spanset containment check (fix perf regression)

Calling a function is super expensive in python. We inline the trivial range
comparison to get back to more sensible performance on common revset operation.

Benchmark result below:

Revision mapping:
0) 3f83fc5cfe71 2.9.2 release
1) bcfd44abad93 current @
2) This revision


revset #0: public()
0) wall 0.010890 comb 0.010000 user 0.010000 sys 0.000000 (best of 201)
1) wall 0.012109 comb 0.010000 user 0.010000 sys 0.000000 (best of 199)
2) wall 0.012211 comb 0.020000 user 0.020000 sys 0.000000 (best of 197)

revset #1: :10000 and public()
0) wall 0.007141 comb 0.010000 user 0.010000 sys 0.000000 (best of 361)
1) wall 0.014139 comb 0.010000 user 0.010000 sys 0.000000 (best of 186)
2) wall 0.008334 comb 0.010000 user 0.010000 sys 0.000000 (best of 308)

revset #2: draft()
0) wall 0.009610 comb 0.010000 user 0.010000 sys 0.000000 (best of 279)
1) wall 0.010942 comb 0.010000 user 0.010000 sys 0.000000 (best of 243)
2) wall 0.011036 comb 0.010000 user 0.010000 sys 0.000000 (best of 239)

revset #3: :10000 and draft()
0) wall 0.006852 comb 0.010000 user 0.010000 sys 0.000000 (best of 383)
1) wall 0.014641 comb 0.010000 user 0.010000 sys 0.000000 (best of 183)
2) wall 0.008314 comb 0.010000 user 0.010000 sys 0.000000 (best of 299)

We can see this changeset gains back the regression for `and` operation on
spanset.  We are still a bit slowerfor the `public()` and `draft()`. Predicates
not touched by this changeset.

Patch

diff --git a/contrib/revsetbenchmarks.txt b/contrib/revsetbenchmarks.txt
--- a/contrib/revsetbenchmarks.txt
+++ b/contrib/revsetbenchmarks.txt
@@ -12,5 +12,9 @@  max(tip:0)
 min(0:tip)
 0::
 min(0::)
 roots((tip~100::) - (tip~100::tip))
 ::p1(p1(tip))::
+public()
+:10000 and public()
+draft()
+:10000 and draft()
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2781,12 +2781,13 @@  class spanset(_orderedsetmixin):
         else:
             for r in iterrange:
                 yield r
 
     def __contains__(self, rev):
-        return self._contained(rev) and not (self._hiddenrevs and rev in
-                self._hiddenrevs)
+        return (((self._end < rev <= self._start)
+                  or (self._start <= rev < self._end))
+                and not (self._hiddenrevs and rev in self._hiddenrevs))
 
     def __nonzero__(self):
         for r in self:
             return True
         return False