Skip to content

Commit 823c0e5

Browse files
authored
Use more aggressive gc thresholds for a big speedup (#18306)
In some cases gc was consuming a significant fraction of CPU, so run gc less often. This made incremental checking of torch 27% faster for me (based on 100 measurements), and also speeds up incremental self check by about 20% and non-incremental self check by about 10%. All measurements were on Python 3.13.
1 parent 0f7a662 commit 823c0e5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mypy/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ def _build(
218218
extra_plugins: Sequence[Plugin],
219219
) -> BuildResult:
220220
if platform.python_implementation() == "CPython":
221-
# This seems the most reasonable place to tune garbage collection.
222-
gc.set_threshold(150 * 1000)
221+
# Run gc less frequently, as otherwise we can spent a large fraction of
222+
# cpu in gc. This seems the most reasonable place to tune garbage collection.
223+
gc.set_threshold(200 * 1000, 30, 30)
223224

224225
data_dir = default_data_dir()
225226
fscache = fscache or FileSystemCache()

0 commit comments

Comments
 (0)