Wednesday 23 May 2007

Improve Default Rails Database Performance

Active Record (AR) is slow. All that nice reflection comes at a price. You should use AR to prototype your app, then take a look at the logs.
1. Sort your development log.
If a database query is only run a few times, let AR handle it. If one is being run a 1000 times then we should pull it out and tweak it.
2. Pull the SQL from the log
Rails has already done the hard work for us, right?
3. Tweak the SQL
Stick the tweaked DB queries in your models and things should move along nicely...

1 comment:

Unknown said...

Thanks Barry, using the find_by_sql is exactly what I did just now to decrease the time to run my tests from over 10 minutes to 24 seconds...

In the words of a certain jazz-program presenter: "Nice..."