|
16 | 16 | import collections |
17 | 17 | import contextlib |
18 | 18 | import errno |
| 19 | +import gc |
19 | 20 | import json |
20 | 21 | import os |
| 22 | +import platform |
21 | 23 | import re |
22 | 24 | import stat |
23 | 25 | import sys |
|
44 | 46 | from mypy.checker import TypeChecker |
45 | 47 | from mypy.error_formatter import OUTPUT_CHOICES, ErrorFormatter |
46 | 48 | from mypy.errors import CompileError, ErrorInfo, Errors, report_internal_error |
47 | | -from mypy.gctune import tune_gc |
48 | 49 | from mypy.graph_utils import prepare_sccs, strongly_connected_components, topsort |
49 | 50 | from mypy.indirection import TypeIndirectionVisitor |
50 | 51 | from mypy.messages import MessageBuilder |
@@ -216,9 +217,10 @@ def _build( |
216 | 217 | stderr: TextIO, |
217 | 218 | extra_plugins: Sequence[Plugin], |
218 | 219 | ) -> 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) |
222 | 224 |
|
223 | 225 | data_dir = default_data_dir() |
224 | 226 | fscache = fscache or FileSystemCache() |
@@ -2372,23 +2374,20 @@ def finish_passes(self) -> None: |
2372 | 2374 | # We should always patch indirect dependencies, even in full (non-incremental) builds, |
2373 | 2375 | # because the cache still may be written, and it must be correct. |
2374 | 2376 | # 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()) |
2377 | 2378 | for _, sym, _ in self.tree.local_definitions(): |
2378 | 2379 | if sym.type is not None: |
2379 | | - symbol_types.add(sym.type) |
| 2380 | + all_types.append(sym.type) |
2380 | 2381 | if isinstance(sym.node, TypeInfo): |
2381 | 2382 | # TypeInfo symbols have some extra relevant types. |
2382 | | - symbol_types.update(sym.node.bases) |
| 2383 | + all_types.extend(sym.node.bases) |
2383 | 2384 | if sym.node.metaclass_type: |
2384 | | - symbol_types.add(sym.node.metaclass_type) |
| 2385 | + all_types.append(sym.node.metaclass_type) |
2385 | 2386 | if sym.node.typeddict_type: |
2386 | | - symbol_types.add(sym.node.typeddict_type) |
| 2387 | + all_types.append(sym.node.typeddict_type) |
2387 | 2388 | 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) |
2392 | 2391 |
|
2393 | 2392 | if self.options.dump_inference_stats: |
2394 | 2393 | dump_type_stats( |
@@ -2417,7 +2416,7 @@ def free_state(self) -> None: |
2417 | 2416 | self._type_checker.reset() |
2418 | 2417 | self._type_checker = None |
2419 | 2418 |
|
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: |
2421 | 2420 | assert None not in types |
2422 | 2421 | valid = self.valid_references() |
2423 | 2422 |
|
|
0 commit comments