Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache version result for each pod and segments #385

Merged
merged 1 commit into from Jun 20, 2017

Conversation

dnkoutso
Copy link
Contributor

@dnkoutso dnkoutso commented Jun 17, 2017

The bigger our internal repo gets the more version comparisons occur. I profiled and saw a 17-20% increase by caching those results which seem safe to cache.

screen_shot_2017-06-16_at_10_24_19_pm

Here's a medium size project 17% improvement.

Before:
real	0m10.410s
user	0m9.156s
sys	0m0.772s

After:
real	0m8.642s
user	0m7.322s
sys	0m0.866s

There is another PR I will do in the main project.

@dnkoutso dnkoutso force-pushed the source_version_performance branch 2 times, most recently from 8bfd34e to db12586 Compare June 17, 2017 05:34
@@ -160,7 +161,8 @@ def versions(name)
raise ArgumentError, 'No name' unless name
pod_dir = pod_path(name)
return unless pod_dir.exist?
pod_dir.children.map do |v|
return @name_to_versions_cache[name] if @name_to_versions_cache.key?(name)
@name_to_versions_cache[name] = pod_dir.children.map do |v|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ||= here instead of checking the key and then setting it?

@@ -24,6 +24,7 @@ class Source
#
def initialize(repo)
@repo = Pathname(repo).expand_path
@name_to_versions_cache = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versions_by_name?
Also, can you see any place where this would need to be invalidated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@segiddins from a look, no I do not see it. The only case I can imagine we might need to invalidate the cache is when we perform update of the repo in source.rb.

However, updating occurs at the beginning before querying for specs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that, it might be correct for us to add code that invalidates when the repo is updated. Just because cocoapods installer calls things in the right order doesn't mean it should be designed as such.

@dnkoutso
Copy link
Contributor Author

Updated.

@dnkoutso
Copy link
Contributor Author

Added spec.

@dnkoutso
Copy link
Contributor Author

Added invalidate cache option when calling update on a repo to be sure. Also added a test.

CHANGELOG.md Outdated
@@ -15,6 +15,10 @@

##### Enhancements

* Cache version result for each pod and segments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong section?

@@ -20,10 +20,15 @@ class Source
#
attr_reader :metadata

# @return [Hash{String=>Array<Version>}] The cache for each pod name to its versions.
#
attr_reader :versions_by_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a cache, I don't think we need to expose it publicly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought about that too...removing

@dnkoutso
Copy link
Contributor Author

All fixed.

@dnkoutso
Copy link
Contributor Author

Rebased

@segiddins
Copy link
Member

👍 nice!

@dnkoutso dnkoutso merged commit f085263 into CocoaPods:master Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants