Cache result of uses_swift and should_build #5837

merged 1 commit into from Sep 14, 2016


None yet

3 participants

dnkoutso commented Sep 10, 2016 edited

We have a large project and our pod install time keeps increasing the more targets and pods we add.

Based on an old profile we did ( it seems that during installation a lot of time is spent for checking if a target can be built or if it uses swift.

This small change speeds up our pod install by a lot (from 1m 40s to about 1m and 3s).

@segiddins the only concern is if that value should be invalidated at any point. For example, is there a chance the prepare_command of a pod generate sources that this change will miss?

@segiddins segiddins and 1 other commented on an outdated diff Sep 11, 2016
@@ -141,9 +141,12 @@ def product_module_name
# A target should not be build if it has no source files.
def should_build?
- source_files = file_accessors.flat_map(&:source_files)
- source_files -= file_accessors.flat_map(&:headers)
- !source_files.empty?
+ return @should_build if defined? @should_build
+ @should_build ||= begin
segiddins Sep 11, 2016 Member

the ||= is redundant, it will never be used, this code will only ever be executed once per instance

dnkoutso Sep 11, 2016 Contributor

Will fix.

segiddins commented Sep 11, 2016 edited

Yes, the prepare_command could change this Since the prepare command isn't run via a PodTarget this should be fine


What's the estimated savings of this change?

dnkoutso commented Sep 11, 2016 edited

I don't have a new profile run to tell you the exact numbers, but as I said in the initial description, it took our pod install time down to 1 minute from 1 minute and ~40 seconds.

In another app it took it down from 23 seconds to 12.

Again this is mostly our environment that has 100+ pods being installed with a lot of files.

Dimitris Couchell-Koutsogiorgas Cache result of uses_swift and should_build 49f6b10

๐Ÿ‘ looks good to me!


Awesome to hear on the prepare command! Thank you for verifying this I was just trying to :)


Hoping to get this landed for 1.1.0!

@segiddins segiddins merged commit ac9250e into CocoaPods:master Sep 14, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

@DanToml I'm ๐Ÿ‘ to back port this if you are

DanToml commented Sep 14, 2016

@segiddins ๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment