Patchwork [1,of,4,STABLE] ui: optimize buffered write with no label

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 24, 2019, 1:09 p.m.
Message ID <ea3f96b253cb2b3f42a2.1548335366@mimosa>
Download mbox | patch
Permalink /patch/37955/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 24, 2019, 1:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1543412184 -32400
#      Wed Nov 28 22:36:24 2018 +0900
# Branch stable
# Node ID ea3f96b253cb2b3f42a224bdd71ff04157b2c33d
# Parent  c953c2a94d68b18c2f3c79262826fdfed743a839
ui: optimize buffered write with no label

This was spotted while making fastannotate faster again after ditching its
own formatter. Since I'm going to inline _write() into ui.write(), I decided
to include this patch in this series.

Here, the cost of '(self.label(a, label) for a in args)' was significant
in hot loops.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1006,8 +1006,8 @@  class ui(object):
 
     def _write(self, dest, *args, **opts):
         if self._isbuffered(dest):
-            if self._bufferapplylabels:
-                label = opts.get(r'label', '')
+            label = opts.get(r'label', '')
+            if label and self._bufferapplylabels:
                 self._buffers[-1].extend(self.label(a, label) for a in args)
             else:
                 self._buffers[-1].extend(args)