Skip to content

Commit f9be1de

Browse files
committed
Merge branch 'master' into faster-tune-gc and simplify
2 parents c85dc0e + 7d81f29 commit f9be1de

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

mypy/build.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import collections
1717
import contextlib
1818
import errno
19+
import gc
1920
import json
2021
import os
22+
import platform
2123
import re
2224
import stat
2325
import sys
@@ -44,7 +46,6 @@
4446
from mypy.checker import TypeChecker
4547
from mypy.error_formatter import OUTPUT_CHOICES, ErrorFormatter
4648
from mypy.errors import CompileError, ErrorInfo, Errors, report_internal_error
47-
from mypy.gctune import tune_gc
4849
from mypy.graph_utils import prepare_sccs, strongly_connected_components, topsort
4950
from mypy.indirection import TypeIndirectionVisitor
5051
from mypy.messages import MessageBuilder
@@ -216,9 +217,10 @@ def _build(
216217
stderr: TextIO,
217218
extra_plugins: Sequence[Plugin],
218219
) -> BuildResult:
219-
# We tune gc in __main__, but also do it here in case we are called from
220-
# another entry point such as a test.
221-
tune_gc()
220+
if platform.python_implementation() == "CPython":
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)
222224

223225
data_dir = default_data_dir()
224226
fscache = fscache or FileSystemCache()
@@ -2372,23 +2374,20 @@ def finish_passes(self) -> None:
23722374
# We should always patch indirect dependencies, even in full (non-incremental) builds,
23732375
# because the cache still may be written, and it must be correct.
23742376
# TODO: find a more robust way to traverse *all* relevant types?
2375-
expr_types = set(self.type_map().values())
2376-
symbol_types = set()
2377+
all_types = list(self.type_map().values())
23772378
for _, sym, _ in self.tree.local_definitions():
23782379
if sym.type is not None:
2379-
symbol_types.add(sym.type)
2380+
all_types.append(sym.type)
23802381
if isinstance(sym.node, TypeInfo):
23812382
# TypeInfo symbols have some extra relevant types.
2382-
symbol_types.update(sym.node.bases)
2383+
all_types.extend(sym.node.bases)
23832384
if sym.node.metaclass_type:
2384-
symbol_types.add(sym.node.metaclass_type)
2385+
all_types.append(sym.node.metaclass_type)
23852386
if sym.node.typeddict_type:
2386-
symbol_types.add(sym.node.typeddict_type)
2387+
all_types.append(sym.node.typeddict_type)
23872388
if sym.node.tuple_type:
2388-
symbol_types.add(sym.node.tuple_type)
2389-
self._patch_indirect_dependencies(
2390-
self.type_checker().module_refs, expr_types | symbol_types
2391-
)
2389+
all_types.append(sym.node.tuple_type)
2390+
self._patch_indirect_dependencies(self.type_checker().module_refs, all_types)
23922391

23932392
if self.options.dump_inference_stats:
23942393
dump_type_stats(
@@ -2417,7 +2416,7 @@ def free_state(self) -> None:
24172416
self._type_checker.reset()
24182417
self._type_checker = None
24192418

2420-
def _patch_indirect_dependencies(self, module_refs: set[str], types: set[Type]) -> None:
2419+
def _patch_indirect_dependencies(self, module_refs: set[str], types: list[Type]) -> None:
24212420
assert None not in types
24222421
valid = self.valid_references()
24232422

mypy/gctune.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)