Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 33799:05264fc9d8d6
util: make nogc effective for CPython
279cd80059d4 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.
Differential Revision: https://phab.mercurial-scm.org/D402
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 14 Aug 2017 22:28:59 -0700 |
parents | bbbbd3c30bfc |
children | ed04d7254a91 |
comparison
equal
deleted
inserted
replaced
33798:2cd5aba5e1d2 | 33799:05264fc9d8d6 |
---|---|
962 allocated even when marked not to be tracked by the collector. Tracking has | 962 allocated even when marked not to be tracked by the collector. Tracking has |
963 no effect on when GCs are triggered, only on what objects the GC looks | 963 no effect on when GCs are triggered, only on what objects the GC looks |
964 into. As a workaround, disable GC while building complex (huge) | 964 into. As a workaround, disable GC while building complex (huge) |
965 containers. | 965 containers. |
966 | 966 |
967 This garbage collector issue have been fixed in 2.7. | 967 This garbage collector issue have been fixed in 2.7. But it still affect |
968 CPython's performance. | |
968 """ | 969 """ |
969 if sys.version_info >= (2, 7): | |
970 return func | |
971 def wrapper(*args, **kwargs): | 970 def wrapper(*args, **kwargs): |
972 gcenabled = gc.isenabled() | 971 gcenabled = gc.isenabled() |
973 gc.disable() | 972 gc.disable() |
974 try: | 973 try: |
975 return func(*args, **kwargs) | 974 return func(*args, **kwargs) |
976 finally: | 975 finally: |
977 if gcenabled: | 976 if gcenabled: |
978 gc.enable() | 977 gc.enable() |
979 return wrapper | 978 return wrapper |
979 | |
980 if pycompat.ispypy: | |
981 # PyPy runs slower with gc disabled | |
982 nogc = lambda x: x | |
980 | 983 |
981 def pathto(root, n1, n2): | 984 def pathto(root, n1, n2): |
982 '''return the relative path from one place to another. | 985 '''return the relative path from one place to another. |
983 root should use os.sep to separate directories | 986 root should use os.sep to separate directories |
984 n1 should use os.sep to separate directories | 987 n1 should use os.sep to separate directories |