# More Associations = Faster

**URL:** <https://www.ruby-forum.com/t/more-associations-faster/125212>\
**Category:** Rails\
**Created:** [January 7, 2008, 4:17am UTC](https://www.ruby-forum.com/t/more-associations-faster/125212 "2008-01-07T04:17:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stimpy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/779978/32.png) [@stimpy](https://www.ruby-forum.com/u/stimpy)\
**Post date:** [January 7, 2008, 4:17am UTC](https://www.ruby-forum.com/t/more-associations-faster/125212/1 "2008-01-07T04:17:25Z")

</div>

I have a Party record that I’m creating from Legacy data stored in  
another  
table in the database, accessed through a model created temporarily:

class Legacy \< ActiveRecord::Base;end

And from that I’m creating records for parties, addresses and contacts  
table. Parties has\_one on both addresses and contacts. I’m doing this  
for  
the first 1000 records in the legacy table and the benchmark I get back  
is,  
using Benchmark.measure:

44.200000 4.150000 48.350000 ( 58.145813)

Which I think to be “OK”, but could be improved.

Now here’s where it gets weird. I added in one more association because  
I  
forgot to add it the first time. This association is another has\_one and  
is  
called client. So again, another 1000 records using Benchmark.measure:

31.280000 3.760000 35.040000 ( 41.497573)

So I made a little ruby script that does this for me, ran the one  
without  
the client first and then ran the one with the client second, and got  
back  
very similar results. So I thought that maybe it was me doing something  
on  
the computer, so I just left it running until the end, and again got  
similar  
results. Reversing the order yielded similar results (WITH client ran  
faster  
than without)

## Why is this happening?

Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.
