Surprisingly basic Rails performance tips – and the people that don’t love them

Antonio Cangiano offers up 10 Ruby on Rails Performance tips, some of which are really just good practice in any web application and aren’t specific to Rails. This includes gems like:

don’t be afraid of using the cool features provided by your database, even if they are not directly supported by Rails and doing so means bypassing ActiveRecord. For example define stored procedures and functions, knowing that you can use them by communicating directly with the database through driver calls, rather than ActiveRecord high level method.

And:

Retrieve only the information that you need. A lot of execution time can be wasted by running selects for data that is not really needed.

Shocking stuff!

What amazes me is the level of irritation evident in the comments from people decrying this as “premature optimization”. I agree that you shouldn’t completely reorganize your code to achieve some speculative performance increase before you really know what parts of your app are going to have issues. However, some things are just common sense. If I can pull back data from the database without doing O(n) queries in a loop, I should do that. If I need to run a report with lots of aggregated data, I should probably consider computing that in the DB via a function or stored procedure. Bottom line, there are things that are guaranteed to cause you problems. Sitting around and smugly saying, “I don’t want to optimize prematurely here” is no excuse for writing dumb code.

(Link to the performance tips via the FiveRuns Blog)

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *