aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2023-09-18 19:18:21 -0700
committergit <svn-admin@ruby-lang.org>2023-11-26 22:07:39 +0000
commit08308fe3e8fd51f4445be9408a418d9ac6960921 (patch)
treeff07be79dbd8244dc512a8b55f2ae4d1f011baff
parentcc5d1bf026bcc5b4929a4f9d5e32d2fa5730348c (diff)
downloadruby-08308fe3e8fd51f4445be9408a418d9ac6960921.tar.gz
[rubygems/rubygems] Reduce allocations when installing gems with bundler
``` ==> memprof.after.txt <== Total allocated: 1.13 MB (2352 objects) Total retained: 10.08 kB (78 objects) ==> memprof.before.txt <== Total allocated: 46.27 MB (38439 objects) Total retained: 9.94 kB (75 objects) ``` Yes, we were allocating 45MB of arrays in `dependencies_installed?`, it was accidentally cubic. https://github.com/rubygems/rubygems/commit/13ab874388
-rw-r--r--lib/bundler/installer/parallel_installer.rb13
-rw-r--r--spec/bundler/bundler/installer/spec_installation_spec.rb6
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb
index 11a90b36cb..02ae7d535f 100644
--- a/lib/bundler/installer/parallel_installer.rb
+++ b/lib/bundler/installer/parallel_installer.rb
@@ -42,8 +42,7 @@ module Bundler
# Checks installed dependencies against spec's dependencies to make
# sure needed dependencies have been installed.
- def dependencies_installed?(all_specs)
- installed_specs = all_specs.select(&:installed?).map(&:name)
+ def dependencies_installed?(installed_specs)
dependencies.all? {|d| installed_specs.include? d.name }
end
@@ -183,8 +182,14 @@ module Bundler
# previously installed specifications. We continue until all specs
# are installed.
def enqueue_specs
- @specs.select(&:ready_to_enqueue?).each do |spec|
- if spec.dependencies_installed? @specs
+ installed_specs = {}
+ @specs.each do |spec|
+ next unless spec.installed?
+ installed_specs[spec.name] = true
+ end
+
+ @specs.each do |spec|
+ if spec.ready_to_enqueue? && spec.dependencies_installed?(installed_specs)
spec.state = :enqueued
worker_pool.enq spec
end
diff --git a/spec/bundler/bundler/installer/spec_installation_spec.rb b/spec/bundler/bundler/installer/spec_installation_spec.rb
index e63ef26cb3..c0ba05ad30 100644
--- a/spec/bundler/bundler/installer/spec_installation_spec.rb
+++ b/spec/bundler/bundler/installer/spec_installation_spec.rb
@@ -47,7 +47,8 @@ RSpec.describe Bundler::ParallelInstaller::SpecInstallation do
all_specs = dependencies + [instance_double("SpecInstallation", :spec => "gamma", :name => "gamma", :installed? => false, :all_dependencies => [], :type => :production)]
spec = described_class.new(dep)
allow(spec).to receive(:all_dependencies).and_return(dependencies)
- expect(spec.dependencies_installed?(all_specs)).to be_truthy
+ installed_specs = all_specs.select(&:installed?).map {|s| [s.name, true] }.to_h
+ expect(spec.dependencies_installed?(installed_specs)).to be_truthy
end
end
@@ -59,7 +60,8 @@ RSpec.describe Bundler::ParallelInstaller::SpecInstallation do
all_specs = dependencies + [instance_double("SpecInstallation", :spec => "gamma", :name => "gamma", :installed? => false, :all_dependencies => [], :type => :production)]
spec = described_class.new(dep)
allow(spec).to receive(:all_dependencies).and_return(dependencies)
- expect(spec.dependencies_installed?(all_specs)).to be_falsey
+ installed_specs = all_specs.select(&:installed?).map {|s| [s.name, true] }.to_h
+ expect(spec.dependencies_installed?(installed_specs)).to be_falsey
end
end
end