53290) [x86_64-darwin15] [aaron@TC ~]$ time ruby -e' ' real 0m0.101s user 0m0.061s sys 0m0.032s [aaron@TC ~]$ time ruby --disable-gems -e' ' real 0m0.051s user 0m0.022s sys 0m0.023s
original_require file rescue LoadError found_gem = all_gems.find do |gem| gem.contains?(file) || gem.contains?(file + ".rb") || gem.contains?(file + ".so") # .bundle on OS X, .dll on Windows end if found_gem found_gem.activate # mutates $LOAD_PATH original_require file else raise "idk lol" end end RubyGems’ Require O(3N) or just O(N)
actionpack-5.0.0.beta2/lib/did_you_mean.bundle actionview-5.0.0.beta2/lib/did_you_mean actionview-5.0.0.beta2/lib/did_you_mean.rb actionview-5.0.0.beta2/lib/did_you_mean.bundle activejob-5.0.0.beta2/lib/did_you_mean activejob-5.0.0.beta2/lib/did_you_mean.rb activejob-5.0.0.beta2/lib/did_you_mean.bundle Why stat file with no extension?
Start to require 'c' Acquire lock for "c" Try to require 'b' Already locked for "b" Finish require 'c' Finish require 'b' Release lock for "c" Release lock for "b"
db:migrate real 0m1.804s user 0m1.487s sys 0m0.414s [aaron@TC omglolwut (master)]$ time COMP=1 RUBYOPT='-I. -rx' bin/rails db:migrate real 0m1.273s user 0m1.002s sys 0m0.374s Before (not compiled) After (compiled)
object.bar end foo Hello.new foo Hello.new `object` is Hello, where is foo? `object` is Hello, I know where foo is. HIT! Cache Contents Key Value [Hello, foo] method source
def bar; end end def foo(object) object.bar end foo Hello.new foo World.new `object` is Hello, where is foo? MISS `object` is World, where is foo? MISS Cache Contents Key Value [Hello, foo] method source
World def bar; end end def foo(object) object.bar end foo Hello.new foo World.new foo Hello.new foo World.new `object` is Hello, where is foo? MISS `object` is World, where is foo? MISS `object` is Hello, I know foo. HIT `object` is World, I know foo. HIT Cache Contents Key Value [Hello, foo] method source [World, foo] method source
0m2.510s user 0m2.453s sys 0m0.024s [aaron@TC ruby (singleton-serial)]$ time ./ruby benchmark/ bm_vm2_poly_singleton.rb real 0m1.380s user 0m1.319s sys 0m0.020s