Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ryan Brunner offered a lot of great advice. Everything he said is true in general, yet did not apply to me.</p> <p>I didn't mention Factory Girl because I didn't think to mention it (don't ask). It turned out to be very relevant detail because it was responsible for the tests running so slow.</p> <p>By simply removing Factory girl completely from my controller tests (I was using <code>Factory.build</code>), I have managed to get them down from 50 seconds to something like 5. </p> <p>The reason is that <code>Factory.build</code> calls <code>Factory.create</code> for associations, which causes a database hit... so if you have a lot of associations, it will take awhile to create a new model object. But even more, that only accounted for 30-35% of the overhead in my case. Factory_girl was actually spending 65-70% of its time doing non-database stuff. I have no idea why, but after forcing every call to be <code>Factory.build</code>, it will still taking quite awhile to build my objects. Going with basic <code>MyClass.new</code> ended up being <strong>MUCH</strong> faster.</p> <p>My entire test suite now takes a little under 30 seconds instead of up to 90 seconds. That is a 300% speed increase in general by making these changes... but when it came to the controller tests, I got a 2000% speed increase - and I was already stubbing! All of that performance overhead was due to <code>Factory.build</code>! That is where most of the gains came from.</p> <p>Of course, I went back into my models and used <code>Factory.build</code> or simply <code>MyClass.new</code> wherever I could.</p> <p>I also added <code>:default_strategy =&gt; :build</code> in <code>factories.rb</code> too whenever I could, to prevent Factory Girl from hitting the database. If you ask me, this should be the default as only 1 test failed as a result of this change, but I managed to get 10 entire seconds out of my model tests by this change alone.</p> <p>If you're having problems like I am, follow these steps and you should notice a 2-3x speed improvement with not much drawback.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload