Skip to content

Commit

Permalink
Optimization to avoid stat() calls from is_module()
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido van Rossum committed Oct 6, 2018
1 parent 78b7cde commit d068bf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/build.py
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions mypy/dmypy_server.py
Expand Up @@ -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)
Expand Down

0 comments on commit d068bf3

Please sign in to comment.