[PATCH] perf: add environment variable to disable GC

Gregory Szorc gregory.szorc at gmail.com
Tue Mar 14 16:07:45 UTC 2017


# 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

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


More information about the Mercurial-devel mailing list