summaryrefslogtreecommitdiff
path: root/gem_prelude.rb
AgeCommit message (Collapse)Author
2016-02-25Reduce system calls by activating the `did_you_mean` gem.tenderlove
Activating the gem puts the gem on the load path, where simply requiring the file will search every gem that's installed until it can find a gem that contains the `did_you_mean` file. Calling RubyGems' `require` will search each installed gem until it can find one that contains the file it should require. This means that the more gems you have installed, the longer it can take to require that gem. To see this in action, lets compare the number of `stat` calls for a "bare require" vs the number of `stat` calls for a require that follows a gem activation by using these two programs: ``` [aaron@TC rubygems (master)]$ cat req_dym.rb begin require 'did_you_mean' rescue LoadError end [aaron@TC rubygems (master)]$ cat gem_dym.rb begin gem 'did_you_mean' require 'did_you_mean' rescue Gem::LoadError, LoadError end ``` The first program just requires the `did_you_mean` gem, where the second one activates the gem, then requires it. We can count the number of `stat` calls using `dtrace`: ``` [aaron@TC rubygems (master)]$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] [aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 283 [aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 13 ``` The "bare require" version does over 10x the number of stat calls compared to the "gem, then require" version. Of course the number for the first one depends on the number of gems you have installed that sort before the `did_you_mean` gem. Lets also look at trunk Ruby: ``` [aaron@TC rubygems (master)]$ ruby -v ruby 2.4.0dev (2016-02-25 trunk 53940) [x86_64-darwin15] [aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 2325 [aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24 685 ``` This change will reduce the number of `stat` calls on trunk Ruby too, but since this installation doesn't have the `did_you_mean` gem, RubyGems is still reading every gem spec file so that it can raise a `Gem::LoadError` exception with a nice error message. If we can modify RubyGems a little, it may be possible to drop the number of stat calls even on a Ruby installation that doesn't have the `did_you_mean` gem. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-09* ruby.c (usage, enable_option, disable_option, process_options): newusa
option `--disable_did_you_mean`. * gem_prelude.rb: now requires did_you_mean gem by default if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-17* ruby.c (process_options): revert r30549.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-15* ruby.c (process_options): autoload rubygems.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-15* ruby.c (ruby_init_prelude): get rid of global namespacenobu
pullution. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-14Reduced gem_prelude to just require rubygems. Reviewed by Evan Phoenixryan
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-16Tue Aug 17 07:38:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>nobu
* gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): include empty suffix. [ruby-core:31730] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-08* gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): return truelynobu
require-able suffixes only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-21Load gems properly. Fixes [ruby-core:31377]evan
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-20Pull rubygem's custom require into gem_preludeevan
This solves the gem loading issue by never touching $LOAD_PATH in gem_prelude and instead loading all of rubygems more quickly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-07* gem_prelude.rb: provide workaround for gem activation. Currently,mame
gem activation does not work by default. Now it can be worked around by requiring "rubygems" first. [ruby-core:29486] a patch from Evan Phoenix in [ruby-core:31096]. * lib/rubygems.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-10Revert r28200.naruse
It caused many failures on test-all and following is SEGV. ./ruby -e 'require %!#{"foo/" * 10000}foo!' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-07* gem_prelude.rb: load full rubygems at LoadError for activationnobu
check. [ruby-core:29486] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-23* gem_prelude.rb (Gem::QuickLoader.load_full_rubygems_library):nobu
suppress a warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-23* gem_prelude.rb (Gem::QuickLoader.load_full_rubygems_library):nobu
get rid of creating same regexps many times. * lib/rubygems/custom_require.rb (Kernel#require): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-12* ruby.c (ruby_init_loadpath_safe): mark initial load paths.nobu
* gem_prelude.rb (push_all_highest_version_gems_on_load_path): search insertion position by initial load path mark. * lib/rubygems.rb (Gem.load_path_insert_index): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-30* gem_prelude.rb (push_all_highest_version_gems_on_load_path):nobu
simplified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-19* gem_prelude.rb (Kernel#gem): should make gem private. a patchmatz
from Sho Hashimoto in [ruby-dev:39838]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-26* gem_prelude.rb (Gem.set_home): must dup before force_encodingnaruse
and must force_encoding before gsub. cf. Yen Sign problem of SJIS [ruby-core:26910] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-05* gem_prelude.rb (Gem.user_home): force_encoding(naruse
Encoding.find('filesystem')). [ruby-core:26525] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-28* encoding.c (get_filesystem_encoding): removed.naruse
* encoding.c (rb_locale_encindex): added. * encoding.c (rb_filesystem_encindex): added. * encoding.c (rb_filesystem_encindex): add an alias 'filesystem'. [ruby-dev:39574] * encoding.c (enc_find): add rdoc about special aliases. * gem_prelude.rb (Gem.set_home): use Encoding.find('filesystem'). * gem_prelude.rb (Gem.set_paths): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-28* gem_prelude.rb (Gem.set_home):naruse
force_encoding(Encoding.filesystem_encoding) [ruby-dev:39546] * gem_prelude.rb (Gem.set_paths): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-30* gem_prelude.rb (Gem.path): uses Gem.default_path as a default valueyugui
so that ruby finds gems in ~/.gem/. (Gem.user_home): reduced version of lib/rubygems.rb's. Gem.default_path needs it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-30* tool/compile_prelude.rb: replaces "require" with in-place evaluationyugui
so that copy & paste for lib/rubygems/default.rb is not necessary. * gem_prelude.rb: removes copied codes from lib/rubygems/defaults.rb. uses require instead. * common.mk (prelude.c): adds dependency for lib/rubygems/defaults.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-15* ext/purelib.rb: translates a fake path to rubygems in $" intoyugui
an alternative in $: so that Kernel.#require does not load more rubygems.rb. Resolves many failures in test/rubygems/*. * gem_prelude.rb (Gem.load_full_rubygems_library): supports case the rubygems to load is not in $(rubylibprefix). (Gem.path_to_full_rubygems_library): new method for the changes in purelib.rb and Gem.load_full_rubygems_library. (Gem.fake_rubygems_as_loaded): new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-06-28* gem_prelude.c (Gem.default_dir): follows the change on yugui
lib/rubygems/default.rb in r23879 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-06-09Update to RubyGems 1.3.4 r2223drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-21* gem_prelude.rb (Gem.default_dir and misc.): use rubylibprefix.yugui
follows the chagne in r23368. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-04-19* gem_prelude.rb (Gem::QuickLoader#push_gem_version_on_load_path):nobu
check for requirement if the gem is installed. a patch from Kyosuke MOROHASHI at [ruby-dev:38020]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-23Match full RubyGems behavior when a gem can't be founddrbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-22Don't remove methods twice. [bug#555]drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-12* encoding.c (enc_get_default_encoding): removed.yugui
Generalizing rb_default_{external,internal}_encoding seems to be difficult. default_external cannot be NULL even before detected. [ruby-dev:37390] * encoding.c (rb_default_external_encoding): has its own implementation again. * encoding.c (rb_default_internal_encoding): ditto. * gem_prelude.rb: added notice. * ruby.c (rubylib_mangled_path, rubylib_mangled_path2): uses locale encoding but not ASCII-8BIT. * ruby.c (process_options): refers less to default_external. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-31Don't require rubygems/defaults from gem_prelude.rb.drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-28merged r19975 and r19978 from ruby_1_9_1 into trunk.yugui
* gem_prelude.rb: considers --program-suffix and prefix configure options. * lib/rubygems/defaults.rb: ditto. * test/rubygems/test_gem.rb (@default_dir_re): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-26* gem_prelude.rb: disables debug and verbose flags to suppress failurenobu
messages. interpolation does not occur inside single quotes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-25Update to RubyGems 1.3.1 r1909.drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-17Fix RubyGems for 1.9, r1780drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-12* ruby.c (ruby_init_gems), gem_prelude.rb: check if Gem is definednobu
instead of Gem::Enable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-12* gem_prelude.rb (load_full_rubygems_library, const_missing): preventnobu
infinite recursion. [ruby-dev:34539] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-31Import RubyGems 1.1.0drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-10Import RubyGems r1601. [ruby-core:15381].drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-24Remove methods from Gem, not QuickLoader, to fix warningsdrbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-23Use require to load rubygems.rb in gem_prelude.rb so the correct path is in ↵drbrain
on RubyGems upgrade. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-22Place bin dir before lib dir so gem bin stubs work.drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-20Import RubyGems 1.0.0, r1575drbrain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-25Import fast-loading gem_prelude.rb from RubyGems.drbrain
Import RubyGems r1516. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-10* gem_prelude.rb: new file for gem libraries. currently empty.akr
* common.mk: generate ext_prelude.c by prelude.rb and gem_prelude.rb. ruby (not miniruby) is linked with ext_prelude.o instead of prelude.o. * inits.c (rb_call_inits): don't call Init_prelude. * ruby.c: support --disable-gems option. (ruby_init_gems): new function to define Gem::Enable and invoke Init_prelude. (process_options): call ruby_init_gems just after ruby_init_loadpath. * tool/compile_prelude.rb: support multiple files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e