Commit feaca01a authored by Marius Rackwitz's avatar Marius Rackwitz

Merge pull request #4399 from danielribeiro/danielrb/improve-deduplicate_targets-performance

improving the performance of Pod::Installer::Analyzer#generate_pod_targets
parents 298c6280 df9b8dbe
...@@ -13,6 +13,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -13,6 +13,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
[#4374](https://github.com/CocoaPods/CocoaPods/issues/4374) [#4374](https://github.com/CocoaPods/CocoaPods/issues/4374)
* Improving the performance of Pod::Installer::Analyzer#generate_pod_targets
[Daniel Ribeiro](https://github.com/danielribeiro)
[#4399](https://github.com/CocoaPods/CocoaPods/pull/4399)
##### Bug Fixes ##### Bug Fixes
* Fix a crash in dependency resolution when running Ruby 2.3. * Fix a crash in dependency resolution when running Ruby 2.3.
......
...@@ -277,6 +277,8 @@ module Pod ...@@ -277,6 +277,8 @@ module Pod
# #
def generate_pod_targets(specs_by_target) def generate_pod_targets(specs_by_target)
if config.deduplicate_targets? if config.deduplicate_targets?
dedupe_cache = {}
all_specs = specs_by_target.flat_map do |target_definition, dependent_specs| all_specs = specs_by_target.flat_map do |target_definition, dependent_specs|
dependent_specs.group_by(&:root).map do |root_spec, specs| dependent_specs.group_by(&:root).map do |root_spec, specs|
[root_spec, specs, target_definition] [root_spec, specs, target_definition]
...@@ -294,7 +296,7 @@ module Pod ...@@ -294,7 +296,7 @@ module Pod
# There are different sets of subspecs or the spec is used across different platforms # There are different sets of subspecs or the spec is used across different platforms
targets_by_distinctors.flat_map do |distinctor, target_definitions| targets_by_distinctors.flat_map do |distinctor, target_definitions|
specs, = *distinctor specs, = *distinctor
generate_pod_target(target_definitions, specs).scoped generate_pod_target(target_definitions, specs).scoped(dedupe_cache)
end end
else else
(specs, _), target_definitions = targets_by_distinctors.first (specs, _), target_definitions = targets_by_distinctors.first
...@@ -308,7 +310,7 @@ module Pod ...@@ -308,7 +310,7 @@ module Pod
dependent_targets = transitive_dependencies_for_pod_target(target, pod_targets) dependent_targets = transitive_dependencies_for_pod_target(target, pod_targets)
target.dependent_targets = dependent_targets target.dependent_targets = dependent_targets
if dependent_targets.any?(&:scoped?) if dependent_targets.any?(&:scoped?)
target.scoped target.scoped(dedupe_cache)
else else
target target
end end
...@@ -317,7 +319,7 @@ module Pod ...@@ -317,7 +319,7 @@ module Pod
pod_targets = specs_by_target.flat_map do |target_definition, specs| pod_targets = specs_by_target.flat_map do |target_definition, specs|
grouped_specs = specs.group_by.group_by(&:root).values.uniq grouped_specs = specs.group_by.group_by(&:root).values.uniq
grouped_specs.flat_map do |pod_specs| 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
end end
pod_targets.each do |target| pod_targets.each do |target|
......
...@@ -57,16 +57,23 @@ module Pod ...@@ -57,16 +57,23 @@ module Pod
@dependent_targets = [] @dependent_targets = []
end end
# @param [Hash{Array => PodTarget}] cache
# the cached PodTarget for a previously scoped (specs, target_definition)
# @return [Array<PodTarget>] a scoped copy for each target definition. # @return [Array<PodTarget>] a scoped copy for each target definition.
# #
def scoped def scoped(cache = {})
target_definitions.map do |target_definition| target_definitions.map do |target_definition|
PodTarget.new(specs, [target_definition], sandbox, true).tap do |target| cache_key = [specs, target_definition]
if cache[cache_key]
cache[cache_key]
else
target = PodTarget.new(specs, [target_definition], sandbox, true)
target.file_accessors = file_accessors target.file_accessors = file_accessors
target.user_build_configurations = user_build_configurations target.user_build_configurations = user_build_configurations
target.native_target = native_target target.native_target = native_target
target.archs = archs 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[cache_key] = target
end end
end 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