Skip to content

Commit ea48612

Browse files
committed
(joe) run find_all_candidates in threadpool to pre-populate cache
1 parent 0de0b8d commit ea48612

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

news/10480.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prepopulate find_all_candidates cache in parallel to reduce overhead when collecting packages to install.

src/pip/_internal/resolution/resolvelib/resolver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import logging
33
import os
4+
from multiprocessing.pool import ThreadPool
45
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, cast
56

67
from pip._vendor.packaging.utils import canonicalize_name
@@ -89,6 +90,17 @@ def resolve(
8990
reporter,
9091
)
9192

93+
def _maybe_find_candidates(req) -> None:
94+
ident = provider.identify(req)
95+
try:
96+
self.factory._finder.find_all_candidates(ident)
97+
except AttributeError:
98+
pass
99+
100+
with ThreadPool() as tp:
101+
for _ in tp.imap_unordered(_maybe_find_candidates, collected.requirements):
102+
pass
103+
92104
try:
93105
try_to_avoid_resolution_too_deep = 2000000
94106
result = self._result = resolver.resolve(

0 commit comments

Comments
 (0)