[PATCH 05 of 10] wireproto: don't format a debug string inside a hot loop

Bryan O'Sullivan bos at serpentine.com
Thu Sep 13 14:01:18 CDT 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1347562629 25200
# Node ID d311c3d3c70fabe73f1053d238fc319ebdee20cb
# Parent  8a634678f1ddf810c61b66752b732e69abd265e8
wireproto: don't format a debug string inside a hot loop

This improves stream_out performance by about 5%.

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -547,13 +547,15 @@
         yield '%d %d\n' % (len(entries), total_bytes)
 
         sopener = repo.sopener
+        debugflag = repo.ui.debugflag
 
         try:
             oldaudit = sopener.mustaudit
             sopener.mustaudit = False
 
             for name, size in entries:
-                repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
+                if debugflag:
+                    repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
                 # partially encode name over the wire for backwards compat
                 yield '%s\0%d\n' % (store.encodedir(name), size)
                 if size <= 65536:
diff --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t
--- a/tests/test-check-code-hg.t
+++ b/tests/test-check-code-hg.t
@@ -6,7 +6,7 @@
   >     exit 80
   > fi
   $ hg manifest | xargs "$check_code" || echo 'FAILURE IS NOT AN OPTION!!!'
-  mercurial/wireproto.py:560:
+  mercurial/wireproto.py:562:
    >                     yield sopener(name).read(size)
    use opener.read() instead
   FAILURE IS NOT AN OPTION!!!


More information about the Mercurial-devel mailing list