From 62959aefc5f74483a0f12921d21210f15f0c9103 Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 8 Jan 2025 11:33:38 +0100 Subject: [PATCH] Improve file pinning comments Not ideal still but it captures the reason why the code is the way it is. Ideally we should remove file pins as it exists now entirely, we're doing a expensive clone (it's noticeable in profiles) of a type that we can still retrieve later only to discard most of them after the resolution is done; But that's out of scope for now. --- crates/uv-resolver/src/pins.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/uv-resolver/src/pins.rs b/crates/uv-resolver/src/pins.rs index b7e96f9b8f9f..6d0d88f655ca 100644 --- a/crates/uv-resolver/src/pins.rs +++ b/crates/uv-resolver/src/pins.rs @@ -12,11 +12,14 @@ use crate::candidate_selector::Candidate; #[derive(Clone, Debug, Default)] pub(crate) struct FilePins(FxHashMap<(PackageName, uv_pep440::Version), ResolvedDist>); +// Inserts are common (every time we select a version) while reads are rare (converting the +// final resolution). impl FilePins { /// Pin a candidate package. pub(crate) fn insert(&mut self, candidate: &Candidate, dist: &CompatibleDist) { self.0 .entry((candidate.name().clone(), candidate.version().clone())) + // Avoid the expensive clone when a version is selected again. .or_insert_with(|| dist.for_installation().to_owned()); } @@ -26,7 +29,6 @@ impl FilePins { name: &PackageName, version: &uv_pep440::Version, ) -> Option<&ResolvedDist> { - // Inserts are common while reads are rare, so the clone here is overall faster. self.0.get(&(name.clone(), version.clone())) } }