Skip to content

Commit

Permalink
Avoid prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 7, 2024
1 parent ab359cc commit 2a1a357
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
3 changes: 2 additions & 1 deletion crates/uv-resolver/src/resolver/batch_prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ impl BatchPrefetcher {
let CandidateDist::Compatible(dist) = candidate.dist() else {
continue;
};
// Avoid building a lot of source distributions.

// Avoid prefetching source distributions, which could be expensive.
if !dist.prefetchable() {
continue;
}
Expand Down
30 changes: 12 additions & 18 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,6 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
// Emit a request to fetch the metadata for this version.
if matches!(&**package, PubGrubPackageInner::Package { .. }) {
if self.index.distributions().register(candidate.version_id()) {
debug!("Fetching metadata for {}=={} ({}) {}", package,
candidate.version(),
filename, dist.for_resolution());
let request = Request::from(dist.for_resolution());
request_sink.blocking_send(request)?;
}
Expand Down Expand Up @@ -1325,7 +1322,6 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag

// Fetch distribution metadata from the distribution database.
Request::Dist(dist) => {
debug!("Fetching metadata for: {dist}", dist = dist);
let metadata = provider
.get_or_build_wheel_metadata(&dist)
.boxed_local()
Expand Down Expand Up @@ -1358,18 +1354,6 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag

// Pre-fetch the package and distribution metadata.
Request::Prefetch(package_name, range) => {
debug!("Searching for prefetch metadata for: {package_name} ({range})");

// Avoid prefetching with unbounded lower-bound ranges.
if !self.selector.use_highest_version(&package_name) {
if let Some((lower, _)) = range.iter().next() {
if lower == &Bound::Unbounded {
debug!("Skipping prefetch for unbounded minimum-version range: {package_name} ({range})");
return Ok(None);
}
}
}

// Wait for the package metadata to become available.
let versions_response = self
.index
Expand Down Expand Up @@ -1419,12 +1403,22 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
return Ok(None);
};

// Avoid prefetching source distributions with unbounded lower-bound ranges.
if !dist.prefetchable() {
if !self.selector.use_highest_version(&package_name) {
if let Some((lower, _)) = range.iter().next() {
if lower == &Bound::Unbounded {
debug!("Skipping prefetch for unbounded minimum-version range: {package_name} ({range})");
return Ok(None);
}
}
}
}

// Emit a request to fetch the metadata for this version.
if self.index.distributions().register(candidate.version_id()) {
let dist = dist.for_resolution().to_owned();

debug!("Prefetching metadata for: {dist}", dist = dist);

let response = match dist {
ResolvedDist::Installable(dist) => {
let metadata = provider
Expand Down

0 comments on commit 2a1a357

Please sign in to comment.