[PATCH 1 of 6 RFC] shrink: instrument sort code to record statistics

Greg Ward greg-hg at gerg.ca
Wed Jan 20 21:15:28 CST 2010


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1263264394 18000
# Node ID 940f9ae7300c9abe5e9af69f42421aa423d34efe
# Parent  c2e27f7966a7a6ba41b2c593a1f258467b8f643b
shrink: instrument sort code to record statistics.
Notably, count:
  - "suboptimal" nodes (predecessor is not first parent)
  - nodes where predecessor is second parent (subset of "suboptimal"
    nodes where we are missing an obvious opportunity to optimize)

diff --git a/contrib/shrink-revlog.py b/contrib/shrink-revlog.py
--- a/contrib/shrink-revlog.py
+++ b/contrib/shrink-revlog.py
@@ -55,8 +55,23 @@
     ui.write('sorting ...')
     visit = root
     ret = []
+
+    # suboptimal: nodes whose predecessor is not first parent
+    # p2pred: nodes whose predecessor is second parent (special case of
+    # suboptimal)
+    suboptimal = p2pred = 0
+
     while visit:
         i = visit.pop(0)
+        # revlog will compute delta relative to ret[-1], so keep track
+        # of nodes where this might result in a large delta
+        parents = rl.parentrevs(i)
+        if ret:
+            if ret[-1] != parents[0]:
+                suboptimal += 1
+            if ret[-1] == parents[1]:
+                p2pred += 1
+
         ret.append(i)
         if i not in children:
             # This only happens if some node's p1 == p2, which can
@@ -70,6 +85,8 @@
                 next.append(c)
         visit = next + visit
     ui.write('\n')
+    ui.write('%d suboptimal nodes\n' % suboptimal)
+    ui.write('%d p2 is predecessor\n' % p2pred)
     return ret
 
 def writerevs(ui, r1, r2, order, tr):


More information about the Mercurial-devel mailing list