Patchwork [2,of,3] perf: store reference to revlog._chunkraw in a local variable

login
register
mail settings
Submitter Gregory Szorc
Date May 6, 2017, 7:19 p.m.
Message ID <71ecddb2aa427e9d3c23.1494098385@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20492/
State Accepted
Headers show

Comments

Gregory Szorc - May 6, 2017, 7:19 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1494097351 25200
#      Sat May 06 12:02:31 2017 -0700
# Node ID 71ecddb2aa427e9d3c2372f5a616ff6cf99cb03f
# Parent  837c542b1c13551524c670ac9c33824aedca2457
perf: store reference to revlog._chunkraw in a local variable

To prepare for renaming revlog._chunkraw, we stuff a reference to this
metho in a local variable. This does 2 things. First, it moves the
attribute lookup outside of a loop, which more accurately measures
the time of the code being invoked. Second, it allows us to alias
to different methods depending on their presence (perf.py needs to
support running against old Mercurial versions).

Removing an attribute lookup from a tigh loop appears to shift the
numbers slightly with mozilla-central:

$ hg perfrevlogchunks -c

! read
! wall 0.354789 comb 0.340000 user 0.330000 sys 0.010000 (best of 28)
! wall 0.335932 comb 0.330000 user 0.290000 sys 0.040000 (best of 30)
! read w/ reused fd
! wall 0.342326 comb 0.340000 user 0.320000 sys 0.020000 (best of 29)
! wall 0.332857 comb 0.340000 user 0.290000 sys 0.050000 (best of 30)
! read batch
! wall 0.023623 comb 0.020000 user 0.000000 sys 0.020000 (best of 124)
! wall 0.023666 comb 0.020000 user 0.000000 sys 0.020000 (best of 125)
! read batch w/ reused fd
! wall 0.023828 comb 0.020000 user 0.000000 sys 0.020000 (best of 124)
! wall 0.023556 comb 0.020000 user 0.000000 sys 0.020000 (best of 126)

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -888,6 +888,7 @@  def perfrevlogchunks(ui, repo, file_=Non
     see ``perfrevlog`` and ``perfrevlogrevision``.
     """
     rl = cmdutil.openrevlog(repo, 'perfrevlogchunks', file_, opts)
+    segmentforrevs = rl._chunkraw
 
     # Verify engines argument.
     if engines:
@@ -919,22 +920,22 @@  def perfrevlogchunks(ui, repo, file_=Non
     def doread():
         rl.clearcaches()
         for rev in revs:
-            rl._chunkraw(rev, rev)
+            segmentforrevs(rev, rev)
 
     def doreadcachedfh():
         rl.clearcaches()
         fh = rlfh(rl)
         for rev in revs:
-            rl._chunkraw(rev, rev, df=fh)
+            segmentforrevs(rev, rev, df=fh)
 
     def doreadbatch():
         rl.clearcaches()
-        rl._chunkraw(revs[0], revs[-1])
+        segmentforrevs(revs[0], revs[-1])
 
     def doreadbatchcachedfh():
         rl.clearcaches()
         fh = rlfh(rl)
-        rl._chunkraw(revs[0], revs[-1], df=fh)
+        segmentforrevs(revs[0], revs[-1], df=fh)
 
     def dochunk():
         rl.clearcaches()
@@ -1003,6 +1004,7 @@  def perfrevlogrevision(ui, repo, file_, 
         raise error.CommandError('perfrevlogrevision', 'invalid arguments')
 
     r = cmdutil.openrevlog(repo, 'perfrevlogrevision', file_, opts)
+    segmentforrevs = r._chunkraw
     node = r.lookup(rev)
     rev = r.rev(node)
 
@@ -1034,7 +1036,7 @@  def perfrevlogrevision(ui, repo, file_, 
     def doread(chain):
         if not cache:
             r.clearcaches()
-        r._chunkraw(chain[0], chain[-1])
+        segmentforrevs(chain[0], chain[-1])
 
     def dorawchunks(data, chain):
         if not cache:
@@ -1062,7 +1064,7 @@  def perfrevlogrevision(ui, repo, file_, 
         r.revision(node)
 
     chain = r._deltachain(rev)[0]
-    data = r._chunkraw(chain[0], chain[-1])[1]
+    data = segmentforrevs(chain[0], chain[-1])[1]
     rawchunks = getrawchunks(data, chain)
     bins = r._chunks(chain)
     text = str(bins[0])