changeset 25344:ceaf04bb14ff

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)
author Yuya Nishihara <yuya@tcha.org>
date Sun, 17 May 2015 15:16:13 +0900
parents 7fbef7932af9
children 8be8c2d3559a
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun May 17 15:11:38 2015 +0900
+++ b/mercurial/revset.py	Sun May 17 15:16:13 2015 +0900
@@ -1922,10 +1922,17 @@
         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
--- a/tests/test-revset.t	Sun May 17 15:11:38 2015 +0900
+++ b/tests/test-revset.t	Sun May 17 15:16:13 2015 +0900
@@ -1011,6 +1011,26 @@
   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'