From d068bf3b8cf43cb32760a47fad5852acf2fa3508 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 6 Oct 2018 16:04:36 -0700 Subject: [PATCH] Optimization to avoid stat() calls from is_module() --- mypy/build.py | 7 +++++++ mypy/dmypy_server.py | 1 + 2 files changed, 8 insertions(+) diff --git a/mypy/build.py b/mypy/build.py index 743fb265beaf9..fcfc50d2a2612 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -604,8 +604,15 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str: return res + _all_modules = None # type: Optional[Set[str]] + + def set_all_modules(self, all_modules: Optional[Set[str]]) -> None: + self._all_modules = all_modules + def is_module(self, id: str) -> bool: """Is there a file in the file system corresponding to module id?""" + if self._all_modules is not None: + return id in self._all_modules return self.find_module_cache.find_module(id) is not None def parse_file(self, id: str, path: str, source: str, ignore_errors: bool) -> MypyFile: diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index 04e100d7f5a88..c50129a03b1ab 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -375,6 +375,7 @@ def fine_grained_increment(self, changed, removed = self.update_changed(sources, add or [], remove or [], update or []) manager.search_paths = compute_search_paths(sources, manager.options, manager.data_dir) + manager.set_all_modules(set(s.module for s in sources)) t1 = time.time() manager.log("fine-grained increment: find_changed: {:.3f}s".format(t1 - t0)) messages = self.fine_grained_manager.update(changed, removed)