Skip to content

Commit

Permalink
fix: small performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager committed Oct 5, 2024
1 parent 59408db commit 75867a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
11 changes: 7 additions & 4 deletions crates/rattler_solve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ license.workspace = true
readme.workspace = true

[dependencies]
rattler_conda_types = { path="../rattler_conda_types", version = "0.28.1", default-features = false }
rattler_digest = { path="../rattler_digest", version = "1.0.2", default-features = false }
rattler_conda_types = { path = "../rattler_conda_types", version = "0.28.1", default-features = false }
rattler_digest = { path = "../rattler_digest", version = "1.0.2", default-features = false }
libc = { workspace = true, optional = true }
chrono = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
itertools = { workspace = true }
url = { workspace = true }
tempfile = { workspace = true }
rattler_libsolv_c = { path="../rattler_libsolv_c", version = "1.0.2", default-features = false, optional = true }
rattler_libsolv_c = { path = "../rattler_libsolv_c", version = "1.0.2", default-features = false, optional = true }
resolvo = { workspace = true, optional = true }
futures = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
bit-set = { version = "0.8.0" }

[dev-dependencies]
criterion = { workspace = true }
insta = { workspace = true, features = ["yaml"] }
once_cell = { workspace = true }
rattler_repodata_gateway = { path = "../rattler_repodata_gateway", default-features = false, features = ["sparse"] }
rattler_repodata_gateway = { path = "../rattler_repodata_gateway", default-features = false, features = [
"sparse",
] }
rstest = { workspace = true }
serde_json = { workspace = true }
similar-asserts = { workspace = true }
Expand Down
26 changes: 16 additions & 10 deletions crates/rattler_solve/src/resolvo/conda_sorting.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bit_set::BitSet;

Check failure on line 1 in crates/rattler_solve/src/resolvo/conda_sorting.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

unused import: `bit_set::BitSet`

Check failure on line 1 in crates/rattler_solve/src/resolvo/conda_sorting.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

unused import: `bit_set::BitSet`

Check failure on line 1 in crates/rattler_solve/src/resolvo/conda_sorting.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

unused import: `bit_set::BitSet`
use std::{
cmp::Ordering,
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -186,15 +187,15 @@ impl<'a, 'repo> SolvableSorter<'a, 'repo> {
unimplemented!("Union requirements, are not implemented in the ordering")
}
});
(*i, dep_ids.collect::<HashSet<_>>())
(*i, dep_ids.collect::<Vec<_>>())
})
.collect_vec();

// Unique names that all entries have in common
let unique_names: HashSet<_> = unique_name_ids(
id_and_deps
.iter()
.map(|(_, names)| names.iter().map(|(name, _)| *name).collect()),
.map(|(_, names)| names.iter().map(|(name, _)| *name)),
);

// Only retain the dependencies for each solvable that are shared by all solvables
Expand Down Expand Up @@ -369,14 +370,19 @@ impl DependencyScores {
}

/// Get the unique package names from a list of vectors of package names.
fn unique_name_ids(vectors: impl IntoIterator<Item = HashSet<NameId>>) -> HashSet<NameId> {
vectors
.into_iter()
.reduce(|mut acc, hs| {
acc.retain(|name| hs.contains(name));
acc
})
.unwrap_or_default()
fn unique_name_ids<V: IntoIterator<Item = NameId>>(
vectors: impl IntoIterator<Item = V>,
) -> HashSet<NameId> {
let mut iter = vectors.into_iter();
let mut intial = match iter.next() {
Some(first) => first.into_iter().collect(),
None => HashSet::new(),
};
for vec in iter {
let set: HashSet<NameId> = vec.into_iter().collect();
intial.retain(|name| set.contains(name));
}
intial
}

pub(super) fn find_highest_version(
Expand Down

0 comments on commit 75867a4

Please sign in to comment.