Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 41066:6603de284b0a
progress: avoid ui.configbool() lookup when progress bar is active
Profiling revealed that the ui.configbool('progress', 'debug') during
progress bar updates was consuming a significant amount of overhead.
This commit adds an attribute on progress bar instances that caches
this config option.
The impact on `hg perfprogress` with default options is significant:
before: ! wall 4.641942 comb 4.580000 user 4.210000 sys 0.370000 (best of 3)
after: ! wall 1.948626 comb 1.950000 user 1.950000 sys 0.000000 (best of 5)
After this change, profiling reveals that progress.progbar.progress()
is now consuming ~73% of time.
This change does not improve the execution time if the progress bar
is disabled. We may want a more comprehensive solution for that case,
as the progress bar won't be enabled in a number of scenarios (e.g.
servers and processes not attached to an interactive TTY).
I also think that overhead of ~2.0s for 1M updates is a bit high.
I suspect further refactoring of the progress bar can significantly
reduce overhead. I don't have plans to do this, however.
Differential Revision: https://phab.mercurial-scm.org/D5408
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 10 Dec 2018 20:06:58 +0000 |
parents | ab92e2111408 |
children | 8ecb17b7f432 |
comparison
equal
deleted
inserted
replaced
41065:0a7f582f6f1f | 41066:6603de284b0a |
---|---|
1700 self._fmsgerr.write(None, type=b'progress', topic=topic, pos=pos, | 1700 self._fmsgerr.write(None, type=b'progress', topic=topic, pos=pos, |
1701 item=item, unit=unit, total=total) | 1701 item=item, unit=unit, total=total) |
1702 elif self._progbar is not None: | 1702 elif self._progbar is not None: |
1703 self._progbar.progress(topic, pos, item=item, unit=unit, | 1703 self._progbar.progress(topic, pos, item=item, unit=unit, |
1704 total=total) | 1704 total=total) |
1705 | |
1706 # Looking up progress.debug in tight loops is expensive. The value | |
1707 # is cached on the progbar object and we can avoid the lookup in | |
1708 # the common case where a progbar is active. | |
1709 if pos is None or not self._progbar.debug: | |
1710 return | |
1711 | |
1712 # Keep this logic in sync with above. | |
1705 if pos is None or not self.configbool('progress', 'debug'): | 1713 if pos is None or not self.configbool('progress', 'debug'): |
1706 return | 1714 return |
1707 | 1715 |
1708 if unit: | 1716 if unit: |
1709 unit = ' ' + unit | 1717 unit = ' ' + unit |