[PATCH 1 of 2 resend] perf: rework perfheads and perftags to clear caches

Bryan O'Sullivan bos at serpentine.com
Sat May 12 12:13:45 CDT 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1336842202 -7200
# Node ID 6e74ed120c0115cf7619ffc0e5f0cab01b5dcb1b
# Parent  94c18a5fdd24857d80c3d4d078f3686d943e8414
perf: rework perfheads and perftags to clear caches

The cache clearing makes numbers more reproducible.

diff -r 94c18a5fdd24 -r 6e74ed120c01 contrib/perf.py
--- a/contrib/perf.py	Sat May 12 19:02:34 2012 +0200
+++ b/contrib/perf.py	Sat May 12 19:03:22 2012 +0200
@@ -45,8 +45,21 @@
     #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, False))))
     timer(lambda: sum(map(len, repo.status())))
 
+def clearcaches(cl):
+    # behave somewhat consistently across internal API changes
+    if util.safehasattr(cl, 'clearcaches'):
+        cl.clearcaches()
+    elif util.safehasattr(cl, '_nodecache'):
+        from mercurial.node import nullid, nullrev
+        cl._nodecache = {nullid: nullrev}
+        cl._nodepos = None
+
 def perfheads(ui, repo):
-    timer(lambda: len(repo.changelog.headrevs()))
+    cl = repo.changelog
+    def d():
+        len(cl.headrevs())
+        clearcaches(cl)
+    timer(d)
 
 def perftags(ui, repo):
     import mercurial.changelog, mercurial.manifest
@@ -125,20 +138,9 @@
     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
     n = repo[rev].node()
     cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
-    # behave somewhat consistently across internal API changes
-    if util.safehasattr(cl, 'clearcaches'):
-        clearcaches = cl.clearcaches
-    elif util.safehasattr(cl, '_nodecache'):
-        from mercurial.node import nullid, nullrev
-        def clearcaches():
-            cl._nodecache = {nullid: nullrev}
-            cl._nodepos = None
-    else:
-        def clearcaches():
-            pass
     def d():
         cl.rev(n)
-        clearcaches()
+        clearcaches(cl)
     timer(d)
 
 def perflog(ui, repo, **opts):


More information about the Mercurial-devel mailing list