[PATCH 5 of 5] revset: add fast path for _list() of integer revisions

Yuya Nishihara yuya at tcha.org
Fri May 29 09:38:08 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1431843373 -32400
#      Sun May 17 15:16:13 2015 +0900
# Node ID f53bd25702c4e79b9f3b7aff7e4344ded0c60132
# Parent  d12328ffb015412492b1ec2266cb643c1a75428f
revset: add fast path for _list() of integer revisions

This can greatly speed up chained 'or' of integer revisions.

1) reduce nesting of chained 'or' operations
2) optimize to a list
3) fast path for integer revisions (this patch)

revset #0: 0 + 1 + 2 + ... + 1000
1) wall 0.483341 comb 0.480000 user 0.480000 sys 0.000000 (best of 20)
2) wall 0.025393 comb 0.020000 user 0.020000 sys 0.000000 (best of 107)
3) wall 0.008371 comb 0.000000 user 0.000000 sys 0.000000 (best of 317)

revset #1: sort(0 + 1 + 2 + ... + 1000)
1) wall 0.035240 comb 0.040000 user 0.040000 sys 0.000000 (best of 100)
2) wall 0.026432 comb 0.030000 user 0.030000 sys 0.000000 (best of 102)
3) wall 0.008418 comb 0.000000 user 0.000000 sys 0.000000 (best of 322)

revset #2: first(0 + 1 + 2 + ... + 1000)
1) wall 0.028949 comb 0.030000 user 0.030000 sys 0.000000 (best of 100)
2) wall 0.025503 comb 0.030000 user 0.030000 sys 0.000000 (best of 106)
3) wall 0.008423 comb 0.010000 user 0.010000 sys 0.000000 (best of 319)

But I admit that it is still slower than the spanset.

revset #3: 0:1000
3) wall 0.000132 comb 0.000000 user 0.000000 sys 0.000000 (best of 19010)

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1922,10 +1922,17 @@ def _list(repo, subset, x):
         return baseset()
     # remove duplicates here. it's difficult for caller to deduplicate sets
     # because different symbols can point to the same rev.
+    cl = repo.changelog
     ls = []
     seen = set()
     for t in s.split('\0'):
-        r = repo[t].rev()
+        try:
+            # fast path for integer revision
+            r = int(t)
+            if str(r) != t or r not in cl:
+                raise ValueError
+        except ValueError:
+            r = repo[t].rev()
         if r in seen:
             continue
         if (r in subset
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1011,6 +1011,26 @@ test unknown revision in `_list`
   abort: unknown revision 'unknown'!
   [255]
 
+test integer range in `_list`
+
+  $ log '-1|-10'
+  9
+  0
+
+  $ log '-10|-11'
+  abort: unknown revision '-11'!
+  [255]
+
+  $ log '9|10'
+  abort: unknown revision '10'!
+  [255]
+
+test '0000' != '0' in `_list`
+
+  $ log '0|0000'
+  0
+  -1
+
 test that chained `or` operations make balanced addsets
 
   $ try '0:1|1:2|2:3|3:4|4:5'


More information about the Mercurial-devel mailing list