diff options
author | The Bundler Bot <bot@bundler.io> | 2016-12-22 13:56:19 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2016-12-22 13:56:19 +0000 |
commit | e236c063b801c55ba9db9b64f95b2bbce709d4ad (patch) | |
tree | b299c0d5aee35abae72f79b7246b0b744cd99c97 | |
parent | 607f372d610f6a946a9005a67d4ffd01c48ed2e2 (diff) | |
parent | c4fa82d688d6c4645bdd29b01ce2bc6dd79d405f (diff) | |
download | bundler-e236c063b801c55ba9db9b64f95b2bbce709d4ad.tar.gz |
Auto merge of #5260 - bundler:seg-require-speed, r=indirect
Improve -rbundler performance
Along with https://github.com/rubygems/rubygems/pull/1801, speeds up `-rbundler` by ~5x
Profiled via
```ruby
# frozen_string_literal: true
REQUIRE_TIMES = {} # rubocop:disable Style/MutableConstant
module Kernel
require "benchmark"
alias_method :require_before_req, :require
def require(path)
ret = nil
Benchmark.realtime do
ret = require_before_req(path)
end.tap do |t|
if ret
from = begin
caller[2]
rescue
nil
end
::REQUIRE_TIMES["#{path} : #{from}"] ||= t
end
end
ret
end
end
at_exit { puts REQUIRE_TIMES.to_a.sort_by(&:last).reverse.map {|k, v| "#{k} =>\n\t#{v}" } }
```
-rw-r--r-- | lib/bundler.rb | 2 | ||||
-rw-r--r-- | lib/bundler/installer/parallel_installer.rb | 4 | ||||
-rw-r--r-- | lib/bundler/plugin/api.rb | 3 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 21 |
4 files changed, 16 insertions, 14 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 0dcaa03965..9b96075ca9 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -7,7 +7,6 @@ require "tmpdir" require "bundler/errors" require "bundler/environment_preserver" -require "bundler/gem_remote_fetcher" require "bundler/plugin" require "bundler/rubygems_ext" require "bundler/rubygems_integration" @@ -32,6 +31,7 @@ module Bundler autoload :FeatureFlag, "bundler/feature_flag" autoload :GemHelper, "bundler/gem_helper" autoload :GemHelpers, "bundler/gem_helpers" + autoload :GemRemoteFetcher, "bundler/gem_remote_fetcher" autoload :GemVersionPromoter, "bundler/gem_version_promoter" autoload :Graph, "bundler/graph" autoload :Index, "bundler/index" diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 12f11bb5f0..c973233d99 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -88,6 +88,10 @@ module Bundler end def call + # Since `autoload` has the potential for threading issues on 1.8.7 + # TODO: remove in bundler 2.0 + require "bundler/gem_remote_fetcher" if RUBY_VERSION < "1.9" + enqueue_specs process_specs until @specs.all?(&:installed?) || @specs.any?(&:failed?) handle_error if @specs.any?(&:failed?) diff --git a/lib/bundler/plugin/api.rb b/lib/bundler/plugin/api.rb index bd7cef5382..a2d5cbb4ac 100644 --- a/lib/bundler/plugin/api.rb +++ b/lib/bundler/plugin/api.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "bundler/plugin/api/source" module Bundler # This is the interfacing class represents the API that we intend to provide @@ -24,6 +23,8 @@ module Bundler # and hooks). module Plugin class API + autoload :Source, "bundler/plugin/api/source" + # The plugins should declare that they handle a command through this helper. # # @param [String] command being handled by them diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 62ade29e30..613609f25f 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -8,6 +8,7 @@ require "bundler/current_ruby" module Gem class Dependency + # This is only needed for RubyGems < 1.4 unless method_defined? :requirement def requirement version_requirements @@ -18,8 +19,6 @@ end module Bundler module SharedHelpers - attr_accessor :gem_loaded - def default_gemfile gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile @@ -217,22 +216,20 @@ module Bundler def bundler_ruby_lib File.expand_path("../..", __FILE__) end - private :bundler_ruby_lib def clean_load_path # handle 1.9 where system gems are always on the load path - if defined?(::Gem) - me = File.expand_path("../../", __FILE__) - me = /^#{Regexp.escape(me)}/ + return unless defined?(::Gem) - loaded_gem_paths = Bundler.rubygems.loaded_gem_paths + bundler_lib = bundler_ruby_lib - $LOAD_PATH.reject! do |p| - next if File.expand_path(p) =~ me - loaded_gem_paths.delete(p) - end - $LOAD_PATH.uniq! + loaded_gem_paths = Bundler.rubygems.loaded_gem_paths + + $LOAD_PATH.reject! do |p| + next if File.expand_path(p).start_with?(bundler_lib) + loaded_gem_paths.delete(p) end + $LOAD_PATH.uniq! end def prints_major_deprecations? |