It's not Ruby that's slow, it's your database
The biggest database performance problem that I have seen time and time again over the 20+ years I&#x27;ve been using sql databases now is caused by people not understanding that databases are <i>relational</i> (ie designed to perform efficiently over tables, not individual rows) and so running code that essentially causes hundreds&#x2F;thousands of individual queries where they could just do one big query. Any time you are doing a select query in a loop you should sit down and take a long hard look at your code.<p>Almost always<p><pre><code>  Do big expensive slow query to get everything I need in one hit
  for each row of result
     do something with it
</code></pre>
is going to be much faster than<p><pre><code>   for each thing in some collection in my program
      get the database row that corresponds to just that one thing
      do something with it
</code></pre>
Round trip io, query parse time, cache effects etc are just going to totally destroy the performance of the second one, and optimising the db or programming language perf is going to do almost nothing to improve things if you&#x27;re doing it this way.  Lots of ORM type abstraction layers make it hard sometimes to see that&#x27;s what you&#x27;re doing, so people blame db performance but they&#x27;re actually doing an insanely inefficient algorithm.<p>My biggest win ever from this was taking an 8 hour operation down to 15s just by moving some sql out of a loop as per the above.