Skip resolved child dependencies in the new resolver if an identical one has already been resolved #6258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#14025
Description
The new dependency resolver queues up all of the children of a dependency as long as they are not suppressed or are direct package references. Depending on your graph, this is fine but in some cases it was discovered that the algorithm would queue up millions of items. This causes restore to be very slow compared to the legacy one and in some cases restore fails with an exception because it cannot create a queue big enough for the items.
This fix checks child dependencies before queuing them. They can be skipped if a resolved dependency has already been selected with the same version and same suppressions. This mimics the same behavior when the resolver dequeues an item to process so this really just keeps dependencies from being queued in the first place.
I also rearranged some checks in an attempt to make perf a little better, there is no point in evaluating runtime dependencies of a child that is going to be skipped.
Unfortunately, there's no good test for this since I was only able to reproduce it with a very large project set. I verified these changes fix that scenario, as well as verified these changes to not break a few other large repositories.
PR Checklist