Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 053a1be

Browse files
authored
Enable --fast-exit by default to speed up mypy (#11541)
Closes #6662. This means that we kill the mypy process at exit instead of cleanly freeing up memory. This speeds up mypy runs by ~10% in some cases (with compiled mypy). We've been using this internally at work for a long time without any issues. Previously the slowdown was visible as a small delay after the final message from mypy was printed. I measured the impact on a branch with some other optimizations as well, so on master the fraction would be slightly less, as other things would be slower. Don't use --fast-exit for runs via the mypy api.
1 parent f9bf649 commit 053a1be

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

mypy/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(args: List[str]) -> Tuple[str, str, int]:
6767
# Lazy import to avoid needing to import all of mypy to call run_dmypy
6868
from mypy.main import main
6969
return _run(lambda stdout, stderr: main(None, args=args,
70-
stdout=stdout, stderr=stderr))
70+
stdout=stdout, stderr=stderr, clean_exit=True))
7171

7272

7373
def run_dmypy(args: List[str]) -> Tuple[str, str, int]:

mypy/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ def main(script_path: Optional[str],
4848
stdout: TextIO,
4949
stderr: TextIO,
5050
args: Optional[List[str]] = None,
51+
clean_exit: bool = False,
5152
) -> None:
5253
"""Main entry point to the type checker.
5354
5455
Args:
5556
script_path: Path to the 'mypy' script (used for finding data files).
5657
args: Custom command-line arguments. If not given, sys.argv[1:] will
57-
be used.
58+
be used.
59+
clean_exit: Don't hard kill the process on exit. This allows catching
60+
SystemExit.
5861
"""
5962
util.check_python_version('mypy')
6063
t0 = time.time()
@@ -66,6 +69,8 @@ def main(script_path: Optional[str],
6669
fscache = FileSystemCache()
6770
sources, options = process_options(args, stdout=stdout, stderr=stderr,
6871
fscache=fscache)
72+
if clean_exit:
73+
options.fast_exit = False
6974

7075
formatter = util.FancyFormatter(stdout, stderr, options.show_error_codes)
7176

@@ -769,7 +774,7 @@ def add_invertible_flag(flag: str,
769774
dest='shadow_file', action='append',
770775
help="When encountering SOURCE_FILE, read and type check "
771776
"the contents of SHADOW_FILE instead.")
772-
add_invertible_flag('--fast-exit', default=False, help=argparse.SUPPRESS,
777+
add_invertible_flag('--fast-exit', default=True, help=argparse.SUPPRESS,
773778
group=internals_group)
774779

775780
report_group = parser.add_argument_group(

mypy/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def __init__(self) -> None:
286286
self.package_root: List[str] = []
287287
self.cache_map: Dict[str, Tuple[str, str]] = {}
288288
# Don't properly free objects on exit, just kill the current process.
289-
self.fast_exit = False
289+
self.fast_exit = True
290290
# Used to transform source code before parsing if not None
291291
# TODO: Make the type precise (AnyStr -> AnyStr)
292292
self.transform_source: Optional[Callable[[Any], Any]] = None

0 commit comments

Comments
 (0)