aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
diff options
context:
space:
mode:
authorSam <sam.saffron@gmail.com>2018-06-06 09:50:58 +1000
committerSam <sam.saffron@gmail.com>2018-06-06 09:50:58 +1000
commita46dcb7454b56c979cded85f2f4f875dcd2cfdf0 (patch)
tree7cb448f2d6764ecbfed081ab0263c6bbd726139b /activerecord/lib/active_record/result.rb
parent32aa7cdd8f031dc756fdde3501efca7ff72bf576 (diff)
downloadrails-a46dcb7454b56c979cded85f2f4f875dcd2cfdf0.tar.gz
rails-a46dcb7454b56c979cded85f2f4f875dcd2cfdf0.tar.bz2
rails-a46dcb7454b56c979cded85f2f4f875dcd2cfdf0.zip
PERF: avoid allocating column names where possible
When requesting columns names from database adapters AR:Result would dup/freeze column names, this prefers using fstrings which cuts down on repeat allocations Attributes that are retained keep these fstrings around for the long term Note, this has the highest impact on "short" result sets, eg: Topic.first where you can void allocating the number of columns * String.
Diffstat (limited to 'activerecord/lib/active_record/result.rb')
-rw-r--r--activerecord/lib/active_record/result.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index e54e8086dd..11626c8e31 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -125,7 +125,7 @@ module ActiveRecord
begin
# We freeze the strings to prevent them getting duped when
# used as keys in ActiveRecord::Base's @attributes hash
- columns = @columns.map { |c| c.dup.freeze }
+ columns = @columns.map(&:-@)
@rows.map { |row|
# In the past we used Hash[columns.zip(row)]
# though elegant, the verbose way is much more efficient