[PATCH] perf: add environment variable to disable GC
Yuya Nishihara
yuya at tcha.org
Sat Mar 18 05:37:26 EDT 2017
On Tue, 14 Mar 2017 09:07:45 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1489507655 25200
> # Tue Mar 14 09:07:35 2017 -0700
> # Node ID 646e03b8d192a064fa58cf8fe74f5dfd6b7e5ee2
> # Parent ed23f929af38e3249a4c0b258939e89782b20795
> perf: add environment variable to disable GC
Nit: "disable GC" and "NOGC" seem a bit confusing since the GC would run
periodically.
> Only hours ago I introduced a gc.collect() to each iteration
> in perf.py. I realized that doing this had the unintended
> side-effect of skewing profiling towards lots of gc-related
> events.
>
> While I still think we should do a gc.collect(), let's add
> an (undocumented) back door to disable gc so profiling
> can yield more meaningful results.
>
> diff --git a/contrib/perf.py b/contrib/perf.py
> --- a/contrib/perf.py
> +++ b/contrib/perf.py
> @@ -31,6 +31,7 @@ from mercurial import (
> cmdutil,
> commands,
> copies,
> + encoding,
> error,
> extensions,
> mdiff,
> @@ -190,7 +191,12 @@ def stub_timer(fm, func, title=None):
> func()
>
> def _timer(fm, func, title=None):
> - gc.collect()
> + # Perform a garbage collection before every timed event to attempt
> + # to mitigate the randomness of gc overhead triggered from previous
> + # operations. Allow it to be disabled so profiling won't be
> + # cluttered with gc events.
> + if 'HGNOGC' not in encoding.environ:
> + gc.collect()
perf.py has to be backward compatible, but encoding.environ is relatively
new. Perhaps config knob would be easier to implement.
More information about the Mercurial-devel
mailing list