Cool Rails Plugin: Scrooge
I have known about this plugin for a while but only recently had the opportunity to play with it a little. The idea behind it is that when we query the database, most of the time we only need a handful of the columns in a table. Rails, however, runs a "
select *" anyway because it doesn't know what you will need. The amount of database overhead can be significantly reduced, however, by only selecting the specific columns that our applications needs.
To combat this, Scrooge watches the queries the application makes at runtime and dynamically adjusts the select statements to only include the columns you are actually using. Your first thought upon hearing that is, "what if it makes a mistake or a different path through the code uses a different field?" Well, if that happens, the plugin will requery the row using the id and get the additional fields it missed. It will also make a note of that and get those fields to begin with next time.
It is extremely easy to use, too. All you need to do is install it as either a gem or plugin and it starts working for you immediately. No configurations, no code to add...it just works. If you don't like it, just back it out and it is all gone. Piece of cake.
Depending on your schema, this could be a large or marginal performance improvement. I expect that in most cases you will see a good performance increase, especially for not having to really do anything to your application. I highly recommend checking it out. Take a look at the project homepage for more details.
http://github.com/methodmissing/scrooge/tree/master