前田です。

またYehuda Katz情報なのですが、Ruby 1.9で、$:の要素が多いとrequireが遅いようです。

defiant:build$ cat t.rb
1000.times {
  $:.push "/opt/ruby/1.8"
}
1000.times do
  require "rational"
end
defiant:build$ time ruby -v t.rb
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
ruby -v t.rb  0.07s user 0.08s system 90% cpu 0.164 total
defiant:build$ time ruby-trunk -v t.rb
ruby 1.9.2dev (2010-03-10 trunk 26866) [i686-linux]
lib/rational.rb is deprecated
ruby-trunk -v t.rb  3.51s user 1.20s system 99% cpu 4.734 total

この例は極端ですが、Gemパッケージがたくさん入っている状態でRailsを
動かしたりすると、結構影響が大きいそうです。

どうも、rb_get_expanded_load_path()が何度も呼ばれるせいでこんなに
遅いようなのですが、$:の中身がすべて絶対パスの時は、expand_pathを
呼ばずにそのまま$:の値を使うようにしてはどうでしょうか。

添付のパッチでかなり早くなりました。

defiant:build$ time ./ruby-trunk -v t.rb
ruby 1.9.2dev (2010-03-11 trunk 26868) [i686-linux]
lib/rational.rb is deprecated
./ruby-trunk -v t.rb  0.28s user 0.01s system 99% cpu 0.293 total

$:に相対パスが入っているとだめですが、幸い1.9では$:から.が削除されて
いますし、require_relativeも使えるので$:に相対パスを入れたいというニーズ
もあまりないんじゃないかと思っています。

-- 
Shugo Maeda
ZGlmZiAtLWdpdCBhL2ZpbGUuYyBiL2ZpbGUuYwppbmRleCA1MDUxNmFkLi40N2Y4NjRiIDEwMDY0
NAotLS0gYS9maWxlLmMKKysrIGIvZmlsZS5jCkBAIC0yNjg3LDggKzI2ODcsNiBAQCBudGZzX3Rh
aWwoY29uc3QgY2hhciAqcGF0aCkKICAgICAodm9pZCkoZXh0ZW5jIHx8IChleHRlbmMgPSByYl9k
ZWZhdWx0X2V4dGVybmFsX2VuY29kaW5nKCkpKSxcCiAgICAgcmJfZW5jX2Fzc29jaWF0ZShyZXN1
bHQsIGV4dGVuYykpCiAKLXN0YXRpYyBpbnQgaXNfYWJzb2x1dGVf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