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

Use resolved parent for resolving children in normalizer #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions src/scala/com/github/johnynek/bazel_deps/Normalizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,23 @@ object Normalizer {
roots.contains(MavenCoordinate(node, v))
}
pickCanonical(node, rootVersion, dups, vcf) match {
case Validated.Valid(m) =>
val newItems = items.map { case (p, _) => (p, Right(m.version)) }
table.updated(node, newItems)
case Validated.Valid(canonical) =>
val newItems = items.map { case (p, _) => (p, Right(canonical.version)) }
table
// fix version of current entry
.updated(node, newItems)
// update all children
.mapValues(_.filter { case (parent, _) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intent seems good, but I think this algorithm is quadratic in the number of nodes.

Going from O(N) to O(N^2) here could be a deal breaker for many repos.

I think we could keep it O(N * E) (where E is the average number of edges nodes) if we use the Graph[N, E] data structure which can look up quickly edges that have a given source or destination. The input graph starts with that, but we may need to update that graph as we modify to use this algorithm.

I'm happy to merge something like this with some tests and as long we don't think we have any quadratic behavior.

Thanks for working on this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is just a prototype to show what would happen. If we agree that this might be a good direction I could try to make it perform better.

// keeps fixed roots
parent.isEmpty ||
// keeps the same version
parent.contains(canonical) ||
// keeps other artifacts
parent.exists(_.unversioned != canonical.unversioned)
// so the same parents with the evicted versions are filtered out
})
// eliminate dependencies we don't need anymore (where the above filter removed everything)
.filter(_._2.nonEmpty)
// requirement is that isAmbiguous(node) is now false
case Validated.Invalid(errorMessages) =>
errorize(node)
Expand Down