[Rubygems-developers] Gem::Specification#copy_of and Rails makes tests startup slow

Gavin Sinclair gsinclair at soyabean.com.au
Fri Dec 10 20:30:41 EST 2004


On Friday, December 10, 2004, 6:07:18 PM, Eric wrote:

>> This is an investigative patch only, so you should be careful to
>> restore the original afterwards.

> Cool, I'll apply this tomorrow and have a report its effectiveness.

I don't think it will make much difference.

Running a small test myself, I'm getting 520 calls to #copy_of.  Note
there's a useless delegation from Spec#copy_of to Spec.copy_of which
I've removed, so that used to be 1440 calls (the profiler doesn't
distinguish the class and instance methods).

That number 520 == (20 locally installed gems) x
                   (26 attributes per gem)

Your number of #copy_of calls (4008) is inflated by:
  - the douple dipping from delegation
  - lazy initialization of attributes)
    * (yes, attrs get initialized up front, but some are nil,
       so they'll get initialized again and again)

Bottom line: if you have a lot of gems installed on your system,
you'll get a lot of calls to #copy_of.  I'm now looking at what can be
done to avoid this.

I think #copy_of is not the only problem, though.  Each "require" is
expensive on my system, it seems.  I'm running a program with some
timing logic:

  require 'rubygems': 0.317000150680542s
  Gem.manage_gems: 4.154999971389771s
  require 'yaml': 0.070000171661377s
  require 'dev-utils/debug': 3.365999937057495s
  require 'log4r': 4.733000040054321s

Anyway, I'm looking into it.

Gavin



More information about the Rubygems-developers mailing list