Re: [PATCH] perf: add environment variable to disable GC

2017-03-18 Thread Yuya Nishihara
On Tue, 14 Mar 2017 09:07:45 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc 
> # 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.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH] perf: add environment variable to disable GC

2017-03-14 Thread Gregory Szorc
# HG changeset patch
# User Gregory Szorc 
# Date 1489507655 25200
#  Tue Mar 14 09:07:35 2017 -0700
# Node ID 646e03b8d192a064fa58cf8fe74f5dfd6b7e5ee2
# Parent  ed23f929af38e3249a4c0b258939e89782b20795
perf: add environment variable to disable GC

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()
 results = []
 begin = util.timer()
 count = 0
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel