Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2cd2406

Browse filesBrowse files
committed
Use fast path in modulefinder more often (#17950)
See #17948 This is about 1.06x faster on `mypy -c 'import torch'` (in both the clean and openai environments) - 19.094 -> 17.896 - 34.161 -> 32.214 ``` λ hyperfine -w 1 -M 3 '/tmp/mypy_primer/timer_mypy_36738b392/venv/bin/mypy -c "import torch" --no-incremental --python-executable clean/bin/python' Benchmark 1: /tmp/mypy_primer/timer_mypy_36738b392/venv/bin/mypy -c "import torch" --no-incremental --python-executable clean/bin/python Time (mean ± σ): 17.896 s ± 0.130 s [User: 16.472 s, System: 1.408 s] Range (min … max): 17.757 s … 18.014 s 3 runs λ hyperfine -w 1 -M 3 '/tmp/mypy_primer/timer_mypy_36738b392/venv/bin/mypy -c "import torch" --no-incremental --python-executable /opt/oai/bin/python' Benchmark 1: /tmp/mypy_primer/timer_mypy_36738b392/venv/bin/mypy -c "import torch" --no-incremental --python-executable /opt/oai/bin/python Time (mean ± σ): 32.214 s ± 0.106 s [User: 29.468 s, System: 2.722 s] Range (min … max): 32.098 s … 32.305 s 3 runs ```
1 parent e20aaee commit 2cd2406
Copy full SHA for 2cd2406

File tree

Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed

‎mypy/build.py

Copy file name to clipboardExpand all lines: mypy/build.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def __init__(
664664
for module in CORE_BUILTIN_MODULES:
665665
if options.use_builtins_fixtures:
666666
continue
667-
path = self.find_module_cache.find_module(module)
667+
path = self.find_module_cache.find_module(module, fast_path=True)
668668
if not isinstance(path, str):
669669
raise CompileError(
670670
[f"Failed to find builtin module {module}, perhaps typeshed is broken?"]
@@ -2725,7 +2725,9 @@ def exist_added_packages(suppressed: list[str], manager: BuildManager, options:
27252725

27262726
def find_module_simple(id: str, manager: BuildManager) -> str | None:
27272727
"""Find a filesystem path for module `id` or `None` if not found."""
2728-
x = find_module_with_reason(id, manager)
2728+
t0 = time.time()
2729+
x = manager.find_module_cache.find_module(id, fast_path=True)
2730+
manager.add_stats(find_module_time=time.time() - t0, find_module_calls=1)
27292731
if isinstance(x, ModuleNotFoundReason):
27302732
return None
27312733
return x
@@ -2734,7 +2736,7 @@ def find_module_simple(id: str, manager: BuildManager) -> str | None:
27342736
def find_module_with_reason(id: str, manager: BuildManager) -> ModuleSearchResult:
27352737
"""Find a filesystem path for module `id` or the reason it can't be found."""
27362738
t0 = time.time()
2737-
x = manager.find_module_cache.find_module(id)
2739+
x = manager.find_module_cache.find_module(id, fast_path=False)
27382740
manager.add_stats(find_module_time=time.time() - t0, find_module_calls=1)
27392741
return x
27402742

‎mypy/modulefinder.py

Copy file name to clipboardExpand all lines: mypy/modulefinder.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
557557
return ModuleNotFoundReason.NOT_FOUND
558558

559559
def find_modules_recursive(self, module: str) -> list[BuildSource]:
560-
module_path = self.find_module(module)
560+
module_path = self.find_module(module, fast_path=True)
561561
if isinstance(module_path, ModuleNotFoundReason):
562562
return []
563563
sources = [BuildSource(module_path, module, None)]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.