Browse files

Performance: reduce garbage created by ActiveRecord::Calculations#col…

  • Loading branch information...
1 parent 229eedf commit 8756dd75b257b17ddda92674d4cc0db307d2153b @josh josh committed Aug 26, 2008
Showing with 8 additions and 1 deletion.
  1. +8 −1 activerecord/lib/active_record/calculations.rb
@@ -260,7 +260,14 @@ def validate_calculation_options(operation, options = {})
# column_alias_for("count(*)") # => "count_all"
# column_alias_for("count", "id") # => "count_id"
def column_alias_for(*keys)
- connection.table_alias_for(keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_'))
+ table_name = keys.join(' ')
+ table_name.downcase!
+ table_name.gsub!(/\*/, 'all')
+ table_name.gsub!(/\W+/, ' ')
+ table_name.strip!
+ table_name.gsub!(/ +/, '_')
+ connection.table_alias_for(table_name)
def column_for(field)

11 comments on commit 8756dd7


michaelklishin replied Aug 28, 2008

Performance work you say. i18n lookups are 60 times slower than Hash access methods, dispatch process still relies on a lot of redundant wrappers around request. And you are doing performance work by removing 5 string instances in a method that is not necessary used on every request… well, great job Joshua.


jeremy replied Aug 28, 2008

It took 5 seconds to pick this low-hanging fruit and, ironically, the points you mention aren’t even hotspots. Lighten up, Michael :)


NZKoz replied Aug 28, 2008

Michael, your comments here are quite antagonistic, and the authority from which you speak is out of proportion to the number of patches you’ve submitted or mailing list threads you’ve participated in.

Perhaps you could just try not commenting for a while, you may find it a lot easier to just let things like this slide rather than getting worked up. Life’s too short to spend your time so angry and rage filled man :)

There seems to be a number of issues on GitHub with double (or triple or quadruple posts). If anyone with access to the GitHub source is reading this, perhaps we should move to either disable the submit button after a request is sent or allow us to delete a post within 5 minutes of posting or both.

Gotta love the fact that xgamerx’s post double-posted… :)


masterkain replied Aug 28, 2008

you too, and probably I’ll do aswell :)

This is getting ridiculous now :P

This is getting ridiculous now

djd replied Aug 28, 2008

The trick to the intentional double post is to ensure that your entries are both the same. :)

geoffgarside replied Aug 28, 2008

Maybe its just an echo because github is so expansive and rock solid


defunkt replied Aug 28, 2008

We’re doing it just to screw with you guys.

(But seriously, I’m looking into this today.)

Please sign in to comment.