Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some performance optimizations after analyzing benchmarks. #5841

Merged
merged 12 commits into from
Aug 22, 2023
Merged
1 change: 1 addition & 0 deletions news/5841.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add back some relevant caching to increase performance after the major refactor released with ``2023.8.19``
8 changes: 7 additions & 1 deletion pipenv/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import os
import sys

try:
from functools import cached_property
except ImportError:
cached_property = property


def _ensure_modules():
spec = importlib.util.spec_from_file_location(
Expand Down Expand Up @@ -226,6 +231,7 @@ def marker_to_str(marker):
return marker_str
return None

@cached_property
def get_cleaned_dict(self):
self.validate_constraints()
if self.entry.extras != self.lockfile_entry.extras:
Expand Down Expand Up @@ -550,7 +556,7 @@ def clean_results(results, resolver, project, category):
reverse_deps=reverse_deps,
category=category,
)
entry_dict = translate_markers(entry.get_cleaned_dict())
entry_dict = translate_markers(entry.get_cleaned_dict)
new_results.append(entry_dict)
return new_results

Expand Down
17 changes: 12 additions & 5 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,24 @@ def prepare_index_lookup(self):
alt_index_lookup[req_name] = index_mapping[index]
return alt_index_lookup

@property
def finder(self):
@cached_property
def package_finder(self):
finder = get_package_finder(
install_cmd=self.pip_command,
options=self.pip_options,
session=self.session,
)
return finder

@property
def finder(self):
finder = self.package_finder
index_lookup = self.prepare_index_lookup()
finder._link_collector.index_lookup = index_lookup
finder._link_collector.search_scope.index_lookup = index_lookup
return finder

@property
@cached_property
def parsed_constraints(self):
pip_options = self.pip_options
pip_options.extra_index_urls = []
Expand Down Expand Up @@ -434,9 +439,10 @@ def get_resolver(self, clear=False):
yield resolver

def resolve(self):
constraints = self.constraints
with temp_environ(), self.get_resolver() as resolver:
try:
results = resolver.resolve(self.constraints, check_supported_wheels=False)
results = resolver.resolve(constraints, check_supported_wheels=False)
except InstallationError as e:
raise ResolutionFailure(message=str(e))
else:
Expand Down Expand Up @@ -512,6 +518,7 @@ def collect_hashes(self, ireq):
return {self.project.get_hash_from_link(self.hash_cache, link)}
return set()

@cached_property
def resolve_hashes(self):
if self.results is not None:
for ireq in self.results:
Expand Down Expand Up @@ -612,7 +619,7 @@ def actually_resolve_deps(
category,
)
resolver.resolve()
hashes = resolver.resolve_hashes()
hashes = resolver.resolve_hashes
resolver.resolve_constraints()
results = resolver.clean_results()
for warning in warning_list:
Expand Down