This is a utility to speedup gem executable scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.

Background:

By default rubygems runs a

require rubygems
...
load Gem.bin_path(name)

in every gem’s auto-generated startup (ex: bin/ruby-prof script).

This is great if you have a complex gem that requires specific version of its dependencies, etc.

However, this template loads full rubygems (even in 1.9), which results in an extra slowdown. In windows, for example, this take an extra 2s, EVERY TIME, at startup.

This can be alleviated, however.

In my box 2s went down to 0.37s (1.9.1 mingw). In linux it can startup a bit faster, too (from 0.3 to 0.16s).

This gem provides a utility to replace the auto-generated startup script with one that caches the Gem.bin_path result so that the second/third/fourth times it starts up using a cached value.

In 1.9, this allows it to avoid loading full rubygems. In 1.8, it relies on the “faster_rubygems” gem, which also avoids loading full rubygems.

How to use it:

# install the gem C:> gem install faster_gem_scripts # now use it to optimize an existing gem, ex: C:> faster_gem_script c:ruby18binredcar

If you want an easy way to discover the gem paths (and are on windows), you can checkout the whichr gem (github.com/rdp/whichr).

Other caveat: if your gem has any “complex dependencies” ,like it uses things like

gem ‘some_other_dependency’, ‘= 1.1.9’ # somewhere inside it

then this system won’t help, because it will be forced to load full rubygems at that point.

You can find out by running it once. If it fails then reinstall the gem in question to get back to its original functionality.

Current problems:

Currently it only works for executables named the same thing as their gem is, ex: redcar’s bin/redcar works redcar’s bin/cucumber does not.

Try it out and see. If it fails then reinstall the gem in question to get back to its original functionality.