@@ -825,18 +825,26 @@ class FindModuleCache:
825
825
826
826
def __init__ (self , fscache : Optional [FileSystemMetaCache ] = None ) -> None :
827
827
self .fscache = fscache or FileSystemMetaCache ()
828
- self .find_lib_path_dirs = functools .lru_cache (maxsize = None )(self ._find_lib_path_dirs )
829
- self .find_module = functools .lru_cache (maxsize = None )(self ._find_module )
828
+ # Cache find_lib_path_dirs: (dir_chain, lib_path)
829
+ self .dirs = {} # type: Dict[Tuple[str, Tuple[str, ...]], List[str]]
830
+ # Cache find_module: (id, lib_path, python_version) -> result.
831
+ self .results = {} # type: Dict[Tuple[str, Tuple[str, ...], Optional[str]], Optional[str]]
830
832
831
833
def clear (self ) -> None :
832
- self .find_module . cache_clear ()
833
- self .find_lib_path_dirs . cache_clear ()
834
+ self .results . clear ()
835
+ self .dirs . clear ()
834
836
835
- def _find_lib_path_dirs (self , dir_chain : str , lib_path : Tuple [str , ...]) -> List [str ]:
837
+ def find_lib_path_dirs (self , dir_chain : str , lib_path : Tuple [str , ...]) -> List [str ]:
836
838
# Cache some repeated work within distinct find_module calls: finding which
837
839
# elements of lib_path have even the subdirectory they'd need for the module
838
840
# to exist. This is shared among different module ids when they differ only
839
841
# in the last component.
842
+ key = (dir_chain , lib_path )
843
+ if key not in self .dirs :
844
+ self .dirs [key ] = self ._find_lib_path_dirs (dir_chain , lib_path )
845
+ return self .dirs [key ]
846
+
847
+ def _find_lib_path_dirs (self , dir_chain : str , lib_path : Tuple [str , ...]) -> List [str ]:
840
848
dirs = []
841
849
for pathitem in lib_path :
842
850
# e.g., '/usr/lib/python3.4/foo/bar'
@@ -845,9 +853,16 @@ def _find_lib_path_dirs(self, dir_chain: str, lib_path: Tuple[str, ...]) -> List
845
853
dirs .append (dir )
846
854
return dirs
847
855
856
+ def find_module (self , id : str , lib_path : Tuple [str , ...],
857
+ python_executable : Optional [str ]) -> Optional [str ]:
858
+ """Return the path of the module source file, or None if not found."""
859
+ key = (id , lib_path , python_executable )
860
+ if key not in self .results :
861
+ self .results [key ] = self ._find_module (id , lib_path , python_executable )
862
+ return self .results [key ]
863
+
848
864
def _find_module (self , id : str , lib_path : Tuple [str , ...],
849
865
python_executable : Optional [str ]) -> Optional [str ]:
850
- """Return the path of the module source file, or None if not found."""
851
866
fscache = self .fscache
852
867
853
868
# If we're looking for a module like 'foo.bar.baz', it's likely that most of the
@@ -2167,14 +2182,12 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
2167
2182
graph = load_graph (sources , manager )
2168
2183
2169
2184
t1 = time .time ()
2170
- fm_cache_size = manager .find_module_cache .find_module .cache_info ().currsize
2171
- fm_dir_cache_size = manager .find_module_cache .find_lib_path_dirs .cache_info ().currsize
2172
2185
manager .add_stats (graph_size = len (graph ),
2173
2186
stubs_found = sum (g .path is not None and g .path .endswith ('.pyi' )
2174
2187
for g in graph .values ()),
2175
2188
graph_load_time = (t1 - t0 ),
2176
- fm_cache_size = fm_cache_size ,
2177
- fm_dir_cache_size = fm_dir_cache_size ,
2189
+ fm_cache_size = len ( manager . find_module_cache . results ) ,
2190
+ fm_dir_cache_size = len ( manager . find_module_cache . dirs ) ,
2178
2191
)
2179
2192
if not graph :
2180
2193
print ("Nothing to do?!" )
0 commit comments