summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Nadeau <julian@jnadeau.ca>2017-03-29 14:27:57 -0400
committerJulian Nadeau <julian@jnadeau.ca>2017-03-30 15:39:23 -0400
commit6e7ed38d503de61a9b3721e06ff7d17bd6e07c11 (patch)
tree40ed2cdb32ed7c4a9349e371f8bb04d7a33cc9a6
parentca7464464a46dc9e2edbb14331828c03248ecfdf (diff)
downloadbundler-6e7ed38d503de61a9b3721e06ff7d17bd6e07c11.tar.gz
Change `definition#converge_dependencies` comparison to an iterator for performance
Previously, a proc was used to extract name and requirements from dependencies. This was done twice, 2*O(n), and compared as Sets. Now that we use a hash for `@locked_deps`, we can iterate one of the arrays (`@dependencies`) and compare against entries in `@locked_deps` with `O(1)` access. This results in `O(n)` access. The result is that `converge_dependencies`, which used to take 26ms, now takes about 13-14ms.
-rw-r--r--lib/bundler/definition.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 5bff85332f..a4aebe95ed 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -695,8 +695,17 @@ module Bundler
dep.platforms.concat(@platforms.map {|p| Dependency::REVERSE_PLATFORM_MAP[p] }.flatten(1)).uniq!
end
end
- dependency_without_type = proc {|d| Gem::Dependency.new(d.name, *d.requirement.as_list) }
- Set.new(@dependencies.map(&dependency_without_type)) != Set.new(@locked_deps.values.map(&dependency_without_type))
+
+ # We want to know if all match, but don't want to check all entries
+ # This means we need to return false if any dependency doesn't match
+ # the lock or doesn't exist in the lock.
+ @dependencies.any? do |dependency|
+ locked_dep = @locked_deps[dependency.name]
+ next true if locked_dep.nil?
+ # We already know the name matches from the hash lookup
+ # so we only need to check the requirement now
+ dependency.requirement != locked_dep.requirement
+ end
end
# Remove elements from the locked specs that are expired. This will most