This project is archived and is in readonly mode.
Quoting in ActiveRecord::Base is inefficient
Reported by Comron Sattari | December 31st, 2009 @ 04:27 PM
During performance testing I noticed queries with many bind variables that are fast on mysql are very slow through rails, I believe this is due to ActiveRecord::Base.connection being called at least once for each bind variable. The following patch is just a demo to show how I got the number of calls reduced by more than a factor of 10, which was about a 50% speed increase for my particular problem.
The column_aliases fix, although we didn't profile it, should help speed up ActiveRecord queries with many joined in columns.
Is the connection something that really needs to be looked up so often, and not just memoized for the entire request? Surely the connection isn't changing between bind variables. :)
Comments and changes to this ticket
-
Comron Sattari December 31st, 2009 @ 04:29 PM
- Tag changed from active to activerecord, active_record, performance
-
Comron Sattari December 31st, 2009 @ 04:29 PM
- no changes were found...
-
Jeremy Kemper January 1st, 2010 @ 02:18 AM
- State changed from new to open
- Assigned user set to Jeremy Kemper
Nice patch! However, it's made against your app's vendor/rails, not Rails itself. Check out the contributor guide for a quick intro to making and submitting changes to Rails: https://rails.lighthouseapp.com/projects/8994/sending-patches
Additional performance work like this is greatly appreciated. Thanks!
-
Marius Nuennerich May 2nd, 2010 @ 05:47 PM
Attached is an updated patch against git master. The last part of Comron's patch didn't apply anymore. I actually did another round of optimization in a second commit, maybe you don't want to commit that. Both tested against PostgreSQL, MySQL and Sqlite.
-
Marius Nuennerich May 16th, 2010 @ 10:53 PM
- Tag changed from activerecord, active_record, performance to activerecord, active_record, bugmash-review, performance
-
Rizwan Reza May 16th, 2010 @ 10:53 PM
- Tag changed from activerecord, active_record, bugmash-review, performance to activerecord, active_record, bugmash, performance
-
Jeremy Kemper May 16th, 2010 @ 11:27 PM
Second patch doesn't apply cleanly. It would be nice to keep Comron as an author on the first commit, by the way:
git commit --amend --author "..."
-
Marius Nuennerich May 16th, 2010 @ 11:56 PM
Ok, I have redone the first part of the patch with amend.
-
pleax May 17th, 2010 @ 12:20 AM
Verified cache_conn.diff from Marius applies cleanly to master and passes tests on mysql and sqlite3.
-
Repository May 17th, 2010 @ 01:43 AM
- State changed from open to committed
(from [e1a340a91d4ee0bbbe8ce1a74b88b3f7e80c1197]) cache connection when quoting
[#3642 state:committed]
Signed-off-by: Marius Nuennerich marius@nuenneri.ch
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/e1a340a91d4ee0bbbe8ce1a74b88b3...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3642 Quoting in ActiveRecord::Base is inefficient [#3642 state:committed]