Skip to content

Commit 3bf7867

Browse files
committed
feat: add cache to resolver in bootstrapper
A long-running bootstrap job may resolve the same requirements specifier many times, especially for packages like setuptools or flit-core. This change adds a cache for all requirements based on their full spec so that if we see the same string more than once we give the same value without going out to the server to look at available packages again. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
1 parent f78a613 commit 3bf7867

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/fromager/bootstrapper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def __init__(
6868
# package.
6969
self._seen_requirements: set[SeenKey] = set()
7070

71+
# Track requirements we have already resolved so we don't resolve them again.
72+
self._resolved_requirements: dict[str, tuple[str, Version]] = {}
73+
7174
self._build_order_filename = self.ctx.work_dir / "build-order.json"
7275

7376
def resolve_version(
@@ -79,6 +82,11 @@ def resolve_version(
7982
8083
Returns the source URL and the version of the requirement.
8184
"""
85+
req_str = str(req)
86+
if req_str in self._resolved_requirements:
87+
logger.debug(f"resolved {req_str} from cache")
88+
return self._resolved_requirements[req_str]
89+
8290
pbi = self.ctx.package_build_info(req)
8391
if pbi.pre_built:
8492
source_url, resolved_version = self._resolve_prebuilt_with_history(
@@ -90,6 +98,8 @@ def resolve_version(
9098
req=req,
9199
req_type=req_type,
92100
)
101+
102+
self._resolved_requirements[req_str] = (source_url, resolved_version)
93103
return source_url, resolved_version
94104

95105
def _processing_build_requirement(self, current_req_type: RequirementType) -> bool:

0 commit comments

Comments
 (0)