Forum: Ruby [ANN] faster_rubygems: speedup rubygems' load time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-05-09 06:21
pleased to announce release of faster_rubygems 0.0.1

description:
A helper to dramatically speedup the time it takes to run
require 'rubygems'
inspired by a request from Yehuda Katz [1] and gem_prelude (and not
knowing if such a utility already existed or not...)

Example speed difference:

bash-3.1$ time ruby examples/require_fast_start.rb

real    0m0.500s
bash-3.1$ time ruby examples/require_rubygems.rb

real    0m1.109s

Yea! Finally ruby script startup times that don't spend forever just
reloading gem paths.

It acts about the same as gem_prelude does (prelude is 1.9 only
currently) -- adds the paths of the highest version of each gem into
your load path so they're ready to be required.

== installation ==

How to install (manual for now--with any interest I could make it
automatic):
find your rubygems.rb file:
ex from ubuntu:
/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb
from doze:
c:\ruby18\lib\ruby\site_ruby\1.8\rubygems.rb

# copy some files into that same directory:

git clone git://github.com/rogerdpack/faster_rubygems.git
cp faster_rubygems/rubygems_*.rb /usr/local/lib/ruby/site_ruby/1.8

== usage ==
instead of
require 'rubygems'
it's
require 'rubygems_fast.rb'
or
require 'rubygems_f.rb' # shortcut to the first method.

Though if you were really clever I suppose you could figure out how to
override the default rubygem behavior to do this, always:)


Speed difference example on linux:
$ time ruby examples/require_rubygems.rb

real    0m0.086s
user    0m0.077s
sys     0m0.008s
$ time ruby examples/require_fast_start.rb

real    0m0.026s
user    0m0.016s
sys     0m0.008s

So better but not "such a big deal" as it is on windows boxes (where it
can use up to 50% of script time).  Also note that that's on warm
start--cold start might show higher differences.  And it's still a 4x
speedup :)
Note also that a few non conforming gems require the use of require
'rubygems' no matter what (they're pretty rare, though--you probably
won't run into them).

Thanks!
-=r

[1]
http://rubyforge.org/tracker/index.php?func=detail...
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-05-09 06:33
(Received via mailing list)
On May 8, 2009, at 21:21, Roger Pack wrote:
> # copy some files into that same directory:
>
> git clone git://github.com/rogerdpack/faster_rubygems.git
> cp faster_rubygems/rubygems_*.rb /usr/local/lib/ruby/site_ruby/1.8

Why didn't you make a gem that does this automatically via a command
line tool or gem plugin?  Not everybody has rubygems.rb installed in
the same place...
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-05-09 08:51
> Why didn't you make a gem that does this automatically via a command
> line tool or gem plugin?  Not everybody has rubygems.rb installed in
> the same place...

great idea.
Now you can just run install.rb within the repo and it will install the
necessary files where they need to go.

I also notice a slight difference in RAM usage--6MB goes to 3MB (that's
on a windows box with maybe 40 total gems).

Thanks.
-=r
This topic is locked and can not be replied to.