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

Importing a bundle gem adds all gems onto the load path (although they are not there) #42

Closed
grahamjenson opened this issue Dec 17, 2019 · 2 comments

Comments

@grahamjenson
Copy link
Contributor

the $LOAD_PATH is the path ruby looks for files to require. the binary_wrapper.tpl adds to the load path using the environment variable RUBYLIB.

With recent updates we have allowed a ruby_library or ruby_binary to specify specifically the gem it requires to be included. This works and only adds the files for that gem to the runfiles of the binary.

However, the LOAD_PATH for all gems are still added.

You can check this by creating a ruby file that just puts $LOAD_PATH and executing it adding only 1 gem, and you will see a path to all gems there. These paths are invalid because the gems files are not included, but since ruby looks through each folder for each require this will make loading files very slow.

@kigster
Copy link
Contributor

kigster commented Dec 17, 2019

Here is a good explanation of this concept: https://thoughtbot.com/blog/following-the-path

Having said that, Ruby process caches LOAD_PATH and if it determines that some of the elements are not valid I am pretty sure this will only cost us once per ruby process. I can confirm that later today.

@kigster
Copy link
Contributor

kigster commented Jan 4, 2020

The $LOAD_PATH in this case is set because we are requiring lib/bundler/setup.rb file in our definitions of the gem library.

Here is an example of this file, given Gemfile for our simple_script example:

require 'rbconfig'
ruby_engine = RUBY_ENGINE
ruby_version = RbConfig::CONFIG["ruby_version"]
path = File.expand_path('..', __FILE__)
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/awesome_print-1.8.0/lib"
$:.unshift "#{path}/"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/colored2-3.1.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/diff-lcs-1.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-19/2.6.0/jaro_winkler-1.5.4"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/jaro_winkler-1.5.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel-1.19.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.6.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rainbow-3.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-support-3.7.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-core-3.7.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-expectations-3.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-mocks-3.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-3.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-its-1.3.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.6.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.78.0/lib"

I am not even sure we need to require this file. Let me verify this.

@kigster kigster closed this as completed Feb 29, 2020
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

No branches or pull requests

2 participants