Commit 384a9587 authored by Daniel Ribeiro's avatar Daniel Ribeiro

improving Pod::Installer::Analyzer#deduplicate_targets performance, by avoiding…

improving Pod::Installer::Analyzer#deduplicate_targets performance, by avoiding computing previously computed dependency trees
parent 298c6280
......@@ -277,6 +277,8 @@ module Pod
#
def generate_pod_targets(specs_by_target)
if config.deduplicate_targets?
dedupe_cache = {}
all_specs = specs_by_target.flat_map do |target_definition, dependent_specs|
dependent_specs.group_by(&:root).map do |root_spec, specs|
[root_spec, specs, target_definition]
......@@ -294,7 +296,7 @@ module Pod
# There are different sets of subspecs or the spec is used across different platforms
targets_by_distinctors.flat_map do |distinctor, target_definitions|
specs, = *distinctor
generate_pod_target(target_definitions, specs).scoped
generate_pod_target(target_definitions, specs).scoped(dedupe_cache)
end
else
(specs, _), target_definitions = targets_by_distinctors.first
......@@ -308,7 +310,7 @@ module Pod
dependent_targets = transitive_dependencies_for_pod_target(target, pod_targets)
target.dependent_targets = dependent_targets
if dependent_targets.any?(&:scoped?)
target.scoped
target.scoped(dedupe_cache)
else
target
end
......@@ -317,7 +319,7 @@ module Pod
pod_targets = specs_by_target.flat_map do |target_definition, specs|
grouped_specs = specs.group_by.group_by(&:root).values.uniq
grouped_specs.flat_map do |pod_specs|
generate_pod_target([target_definition], pod_specs).scoped
generate_pod_target([target_definition], pod_specs).scoped(dedupe_cache)
end
end
pod_targets.each do |target|
......
......@@ -59,14 +59,19 @@ module Pod
# @return [Array<PodTarget>] a scoped copy for each target definition.
#
def scoped
def scoped(cache = {})
target_definitions.map do |target_definition|
PodTarget.new(specs, [target_definition], sandbox, true).tap do |target|
cash_key = [specs, target_definition]
if cache[cash_key]
cache[cash_key]
else
target = PodTarget.new(specs, [target_definition], sandbox, true)
target.file_accessors = file_accessors
target.user_build_configurations = user_build_configurations
target.native_target = native_target
target.archs = archs
target.dependent_targets = dependent_targets.flat_map(&:scoped).select { |pt| pt.target_definitions == [target_definition] }
target.dependent_targets = dependent_targets.flat_map { |pt| pt.scoped(cache)}.select { |pt| pt.target_definitions == [target_definition] }
cache[cash_key] = target
end
end
end
......
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