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

perf: invalidate less contradicted_incompatibilities #170

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ pub struct State<P: Package, VS: VersionSet, Priority: Ord + Clone> {

incompatibilities: Map<P, Vec<IncompId<P, VS>>>,

/// Store the ids of incompatibilities that are already contradicted
/// and will stay that way until the next conflict and backtrack is operated.
contradicted_incompatibilities: rustc_hash::FxHashSet<IncompId<P, VS>>,
/// Store the ids of incompatibilities that are already contradicted.
/// For each one keep track of the decision level when it was found to be contradicted.
/// These will stay contradicted until we have backtracked beyond its associated decision level.
contradicted_incompatibilities: Map<IncompId<P, VS>, DecisionLevel>,

/// All incompatibilities expressing dependencies,
/// with common dependents merged.
Expand Down Expand Up @@ -62,7 +63,7 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
root_package,
root_version,
incompatibilities,
contradicted_incompatibilities: rustc_hash::FxHashSet::default(),
contradicted_incompatibilities: Map::default(),
partial_solution: PartialSolution::empty(),
incompatibility_store,
unit_propagation_buffer: SmallVec::Empty,
Expand Down Expand Up @@ -111,7 +112,10 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
let mut conflict_id = None;
// We only care about incompatibilities if it contains the current package.
for &incompat_id in self.incompatibilities[&current_package].iter().rev() {
if self.contradicted_incompatibilities.contains(&incompat_id) {
if self
.contradicted_incompatibilities
.contains_key(&incompat_id)
{
continue;
}
let current_incompat = &self.incompatibility_store[incompat_id];
Expand All @@ -135,10 +139,12 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
&self.incompatibility_store,
);
// With the partial solution updated, the incompatibility is now contradicted.
self.contradicted_incompatibilities.insert(incompat_id);
self.contradicted_incompatibilities
.insert(incompat_id, self.partial_solution.current_decision_level());
}
Relation::Contradicted(_) => {
self.contradicted_incompatibilities.insert(incompat_id);
self.contradicted_incompatibilities
.insert(incompat_id, self.partial_solution.current_decision_level());
}
_ => {}
}
Expand All @@ -155,7 +161,8 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
);
// After conflict resolution and the partial solution update,
// the root cause incompatibility is now contradicted.
self.contradicted_incompatibilities.insert(root_cause);
self.contradicted_incompatibilities
.insert(root_cause, self.partial_solution.current_decision_level());
}
}
// If there are no more changed packages, unit propagation is done.
Expand Down Expand Up @@ -220,7 +227,9 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
) {
self.partial_solution
.backtrack(decision_level, &self.incompatibility_store);
self.contradicted_incompatibilities.clear();
// Remove contradicted incompatibilities that depend on decisions we just backtracked away.
self.contradicted_incompatibilities
.retain(|_, dl| *dl <= decision_level);
if incompat_changed {
self.merge_incompatibility(incompat);
}
Expand Down
4 changes: 4 additions & 0 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
.unwrap();
decision_level.max(DecisionLevel(1))
}

pub fn current_decision_level(&self) -> DecisionLevel {
self.current_decision_level
}
}

impl<P: Package, VS: VersionSet> PackageAssignments<P, VS> {
Expand Down