Skip to content

Commit

Permalink
(joe) run find_all_candidates in threadpool to pre-populate cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jbylund committed Sep 16, 2021
1 parent 0de0b8d commit ea48612
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/10480.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prepopulate find_all_candidates cache in parallel to reduce overhead when collecting packages to install.
12 changes: 12 additions & 0 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging
import os
from multiprocessing.pool import ThreadPool
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, cast

from pip._vendor.packaging.utils import canonicalize_name
Expand Down Expand Up @@ -89,6 +90,17 @@ def resolve(
reporter,
)

def _maybe_find_candidates(req) -> None:
ident = provider.identify(req)
try:
self.factory._finder.find_all_candidates(ident)
except AttributeError:
pass

with ThreadPool() as tp:
for _ in tp.imap_unordered(_maybe_find_candidates, collected.requirements):
pass

try:
try_to_avoid_resolution_too_deep = 2000000
result = self._result = resolver.resolve(
Expand Down

0 comments on commit ea48612

Please sign in to comment.