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

Bryan O'Sullivan bos at serpentine.com
Tue Apr 17 16:26:26 CDT 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1334697594 25200
# Node ID 083221aa0d705cafa8b2588af149b6dabf0fcf28
# Parent  91196ebcaeed06217427e08b879e761dc79472c7
perf: rework perfheads and perftags to clear caches

The cache clearing makes numbers more reproducible.

diff -r 91196ebcaeed -r 083221aa0d70 contrib/perf.py
--- a/contrib/perf.py	Mon Apr 16 22:41:03 2012 -0700
+++ b/contrib/perf.py	Tue Apr 17 14:19:54 2012 -0700
@@ -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