Skip to content
Browse files

Merge pull request #12185 from SamSaffron/join_dep

Reduce allocations when extracting AR models
  • Loading branch information...
2 parents 2a0f260 + 14b23ee commit 919547ccfb0d7be5aeea29abe48837b27136c8da @rafaelfranca rafaelfranca committed
Showing with 13 additions and 1 deletion.
  1. +13 −1 activerecord/lib/active_record/associations/join_dependency/join_part.rb
View
14 activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -62,7 +62,19 @@ def column_names_with_alias
end
def extract_record(row)
- Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}]
+ # This code is performance critical as it is called per row.
+ # see: https://github.com/rails/rails/pull/12185
+ hash = {}
+
+ index = 0
+ length = column_names_with_alias.length
+ while index < length
+ column_name,alias_name = column_names_with_alias[index]
+ hash[column_name] = row[alias_name]
+ index += 1
+ end
+
+ hash
end
def record_id(row)

0 comments on commit 919547c

Please sign in to comment.
Something went wrong with that request. Please try again.