Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
PERFORMANCE: Properly cache gems_size result for each requirement. Cl…
Browse files Browse the repository at this point in the history
…oses #1511

This speeds up to 3x times resolve method under some specific
circunstances
  • Loading branch information
spastorino committed Dec 17, 2011
1 parent fb55494 commit ae592a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def successify(activated)

def start(reqs)
activated = {}
@gems_size = Hash[reqs.map { |r| [r, gems_size(r)] }]

resolve(reqs, activated)
end
Expand All @@ -176,7 +177,7 @@ def resolve(reqs, activated)
[ activated[a.name] ? 0 : 1,
a.requirement.prerelease? ? 0 : 1,
@errors[a.name] ? 0 : 1,
activated[a.name] ? 0 : gems_size(a) ]
activated[a.name] ? 0 : @gems_size[a] ]
end

debug { "Activated:\n" + activated.values.map {|a| " #{a}" }.join("\n") }
Expand Down Expand Up @@ -210,7 +211,13 @@ def resolve(reqs, activated)
# I have no idea if this is the right way to do it, but let's see if it works
# The current requirement might activate some other platforms, so let's try
# adding those requirements here.
reqs.concat existing.activate_platform(current.__platform)
dependencies = existing.activate_platform(current.__platform)
reqs.concat dependencies

dependencies.each do |dep|
next if dep.type == :development
@gems_size[dep] = gems_size(dep)
end

resolve(reqs, activated)
else
Expand Down Expand Up @@ -325,6 +332,7 @@ def resolve_requirement(spec_group, requirement, reqs, activated)
debug { " * #{dep.name} (#{dep.requirement})" }
dep.required_by.replace(requirement.required_by)
dep.required_by << requirement
@gems_size[dep] = gems_size(dep)
reqs << dep
end

Expand Down

0 comments on commit ae592a9

Please sign in to comment.