Patchwork [2,of,2] revset.children: ignore rev numbers that are too low

mail settings
Submitter Siddharth Agarwal
Date Dec. 7, 2012, 6:57 p.m.
Message ID <21d3f231d0b2b7c04e80.1354906620@sid0x220>
Download mbox | patch
Permalink /patch/30/
State Accepted
Commit 34a1a639d8358e43f4bcba7b0cff19f4e4e6958d
Headers show


Siddharth Agarwal - Dec. 7, 2012, 6:57 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0 at>
# Date 1354905463 28800
# Node ID 21d3f231d0b2b7c04e8016d3bbdaefcd4258b0a6
# Parent  3d2dd6342dcd106626fb3b19048cab03a59f6296
revset.children: ignore rev numbers that are too low

This replaces unnecessary parentrevs() calls with calculating min(parentset).
Even though the min operation is O(size of parentset), since parentrevs is
relatively expensive, this tradeoff almost always works in our favour. In a
repository with over 400,000 changesets, hg perfrevset "children(X)" takes:

       Set X       Before    After
       -1           0.51s    0.06s
    -1000:          0.55s    0.08s
   -10000:          0.56s    0.10s
  -100000:          0.60s    0.25s
  -100000:-99000    0.55s    0.19s
        0:100000    0.60s    0.61s
      all()         0.72s    0.74s

The relative performance is similar for Mercurial's own repository -- several
times faster in most cases, slightly slower for revisions close to 0 and


diff -r 3d2dd6342dcd -r 21d3f231d0b2 mercurial/
--- a/mercurial/	Thu Dec 06 11:21:11 2012 -0800
+++ b/mercurial/	Fri Dec 07 10:37:43 2012 -0800
@@ -488,8 +488,13 @@ 
 def _children(repo, narrow, parentset):
     cs = set()
+    if not parentset:
+        return cs
     pr = repo.changelog.parentrevs
+    minrev = min(parentset)
     for r in narrow:
+        if r <= minrev:
+            continue
         for p in pr(r):
             if p in parentset: