{"action":"opened","issue":{"url":"https://api.github.com/repos/rubygems/rubygems/issues/1358","labels_url":"https://api.github.com/repos/rubygems/rubygems/issues/1358/labels{/name}","comments_url":"https://api.github.com/repos/rubygems/rubygems/issues/1358/comments","events_url":"https://api.github.com/repos/rubygems/rubygems/issues/1358/events","html_url":"https://github.com/rubygems/rubygems/issues/1358","id":111408314,"number":1358,"title":"\"gem\" calls slow subsequent requires to stdlib","user":{"login":"TiagoCardoso1983","id":215707,"avatar_url":"https://avatars.githubusercontent.com/u/215707?v=3","gravatar_id":"","url":"https://api.github.com/users/TiagoCardoso1983","html_url":"https://github.com/TiagoCardoso1983","followers_url":"https://api.github.com/users/TiagoCardoso1983/followers","following_url":"https://api.github.com/users/TiagoCardoso1983/following{/other_user}","gists_url":"https://api.github.com/users/TiagoCardoso1983/gists{/gist_id}","starred_url":"https://api.github.com/users/TiagoCardoso1983/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TiagoCardoso1983/subscriptions","organizations_url":"https://api.github.com/users/TiagoCardoso1983/orgs","repos_url":"https://api.github.com/users/TiagoCardoso1983/repos","events_url":"https://api.github.com/users/TiagoCardoso1983/events{/privacy}","received_events_url":"https://api.github.com/users/TiagoCardoso1983/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-14T14:17:53Z","updated_at":"2015-10-14T14:17:53Z","closed_at":null,"body":"Running in a system with GlusterFS setup, we're experiencing very slow performance in scripts which only load ruby libraries. The scripts belong to a gem with a fair amount of dependencies, and are installed in the system and available to all users, which means, rubygems has to parse all of the gemspecs available.  Every subsequent call to the my \"test\" script will load the gem (let's call it 'ruby-test'):\r\n\r\n```ruby\r\n# possible binstub for my test script\r\nrequire 'rubygems'\r\n...\r\ngem 'ruby-test', version\r\nload Gem.bin('ruby-test', 'test', version)\r\n```\r\n\r\nmy script only has the following:\r\n\r\n```ruby\r\n!#/usr/bin/env ruby\r\nrequire 'abbrev'\r\nputs \"test\"\r\n```\r\n\r\nThe \"problem\" seems to be the \"gem\" call in the bin stub. This will load all dependencies in my gem's gemspec and prepend them to ```$LOAD_PATH```, which means, every subsequent require will first be looked up in the dependencies tree before reaching the ruby stdlib, and that represents a performance penalty for requiring 'abbrev', because I cannot control the my dependency trees. ruby itself doesn't have a huge amount of internal libraries, which should make lookups very fast. \r\n\r\nThis seems to be the \"culprit\":\r\n\r\nhttps://github.com/rubygems/rubygems/blob/c18805ca48f533fbde40025df41a8f817cd6ff48/lib/rubygems.rb#L575-L587\r\n\r\nThis method returns 0, which means, calls to ```gem``` will effectively prepend the gem paths in ```$LOAD_PATH```.\r\n\r\nNow, I don't know if this is a \"bug\", or just the way rubygems is designed, with the assumption that all gem executables require all dependencies. But this decision increases exponentially the number of ```lstat```and ```stat``` syscalls, which is noticeably even worse when a distributed file system is involved. \r\n\r\nWouldn't it be best do \"prepend\" dependencies after the ruby stdlib paths?\r\n\r\n"}}