D402: util: make nogc effective for CPython

quark (Jun Wu) phabricator at mercurial-scm.org
Tue Aug 15 05:33:59 UTC 2017


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  https://phab.mercurial-scm.org/rHG279cd80059d41bbdb91ea9073278cbbe7f1b43d5 made `util.nogc` a no-op. It was to optimize PyPy. But it slows
  down CPython if many objects (like 300k+) are created.
  
  For example, running `hg log -r .` without extensions in `hg-committed` with
  14k+ obsmarkers have the following times:
  
    before        | after
    hg    | chg   | hg    | chg
    -----------------------------
    1.262 | 0.860 | 1.077 | 0.619 (seconds, best of 20 runs)
  
  Therefore let's re-enable nogc for CPython.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D402

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -938,10 +938,9 @@
     into. As a workaround, disable GC while building complex (huge)
     containers.
 
-    This garbage collector issue have been fixed in 2.7.
+    This garbage collector issue have been fixed in 2.7. But it still affect
+    CPython's performance.
     """
-    if sys.version_info >= (2, 7):
-        return func
     def wrapper(*args, **kwargs):
         gcenabled = gc.isenabled()
         gc.disable()
@@ -952,6 +951,10 @@
                 gc.enable()
     return wrapper
 
+if pycompat.ispypy:
+    # PyPy runs slower with gc disabled
+    nogc = lambda x: x
+
 def pathto(root, n1, n2):
     '''return the relative path from one place to another.
     root should use os.sep to separate directories



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list