Commit 54b0c132 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Resolver] Sort dependencies by number of possibilities, improving performance…

[Resolver] Sort dependencies by number of possibilities, improving performance exponentially on large Podfiles
parent 14486bbe
...@@ -122,6 +122,8 @@ module Pod ...@@ -122,6 +122,8 @@ module Pod
end end
def search_for(dependency) def search_for(dependency)
@search ||= {}
@search[dependency] ||= begin
prerelease_requirement = dependency. prerelease_requirement = dependency.
requirement. requirement.
requirements. requirements.
...@@ -136,6 +138,8 @@ module Pod ...@@ -136,6 +138,8 @@ module Pod
compact. compact.
each { |s| s.version.head = dependency.head? } each { |s| s.version.head = dependency.head? }
end end
@search[dependency].dup
end
def dependencies_for(dependency) def dependencies_for(dependency)
dependency.all_dependencies dependency.all_dependencies
...@@ -155,6 +159,24 @@ module Pod ...@@ -155,6 +159,24 @@ module Pod
end end
end end
# Sort dependencies so that the ones that are easiest to resolve are first.
# Easiest to resolve is (usually) defined by:
# 1) Is this dependency already activated?
# 2) How relaxed are the requirements?
# 3) Are there any conflicts for this dependency?
# 4) How many possibilities are there to satisfy this dependency?
#
def sort_dependencies(dependencies, activated, conflicts)
dependencies.sort_by do |dependency|
name = name_for(dependency)
[
activated.vertex_named(name).payload ? 0 : 1,
conflicts[name] ? 0 : 1,
search_for(dependency).count,
]
end
end
# @return [Hash{Podfile::TargetDefinition => Array<Specification>}] # @return [Hash{Podfile::TargetDefinition => Array<Specification>}]
# returns the resolved specifications grouped by target. # returns the resolved specifications grouped by target.
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment