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

Eric Hodel drbrain at segment7.net
Fri Dec 10 02:07:18 EST 2004

On 09 Dec 2004, at 17:52, Gavin Sinclair wrote:

> On Thursday, December 2, 2004, 5:13:37 PM, Eric wrote:
>> I have a small testcase in rails that has 7 tests in it (4 of them
>> raise NotImplementedError), but simply starting up the testcase takes 
>> 3
>> seconds:
>> $ ruby -r profile -Ilib:test test/unit/emailer_test.rb
>>    %   cumulative   self              self     total
>>   time   seconds   seconds    calls  ms/call  ms/call  name
>>   18.37     5.57      5.57      462    12.06    19.42  Integer#gcd
>>   10.26     8.68      3.11     4008     0.78     2.37  
>> Gem::Specification#copy_of
> I'm looking into this now, Eric.  4008 is a lot of calls.  See bottom
> of email for a patch you can try to see if it gets reduced.
>> [...] Is all the copying done in #copy_of completely necessary?

[snip lots of good info]

> Do you see the need for the copy_of?  The default value for the
> attributes is held in a class variable.  The reader lazily sets the
> instance variable to the default value.  We must take a copy of the
> default value, otherwise every Specification object will be pointing
> to the same array of files, for instance.

I was quite sure there was a valid need for the copying, but I was 
unsure if anybody realized the extent of its consequences.  If I come 
across #dup in someone's code, I'm pretty sure that removing it is 
going to break things catastrophically, subtly, or both.

> Now, let's challenge some of the thinking behind all this.

[snip challenged thinking]

> Eric, if you're still reading, you can help investigate this issue by
> applying a simple patch (at bottom of email) against the latest
> specification.rb (which shipped with RubyGems 0.8.3).  Run your tests
> again, and see how many calls are made to #copy_of, and see if
> anything breaks.
> 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.

More information about the Rubygems-developers mailing list