aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-09-28 10:37:28 -0400
committerSean Griffin <sean@seantheprogrammer.com>2015-09-28 10:42:09 -0400
commit3e408a2654727b49ee0e054e27a4f4ca199f72a7 (patch)
tree38a478f44d0a1b44e5165db50644702d0859afba /activesupport
parent58750422c57e0cdc7f0a4ab4030fb9a98ec0b9db (diff)
downloadrails-3e408a2654727b49ee0e054e27a4f4ca199f72a7.tar.gz
rails-3e408a2654727b49ee0e054e27a4f4ca199f72a7.tar.bz2
rails-3e408a2654727b49ee0e054e27a4f4ca199f72a7.zip
Speed up `Hash#transform_values` when empty
We're calling this function on an empty hash as part of copying the attribute set during dirty checking initialization. The new structure caused a performance regression on loading records from the database. This causes `User.all.to_a` to perform about 10% faster w/ 10k records. Calculating ------------------------------------- User.all - master 9.000 i/100ms User.all - sg-fix-ar-regression 8.000 i/100ms ------------------------------------------------- User.all - master 81.236 (± 7.4%) i/s - 405.000 User.all - sg-fix-ar-regression 89.716 (± 7.8%) i/s - 448.000
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/transform_values.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/transform_values.rb b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
index e9bcce761f..6b3402b2c9 100644
--- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb
+++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
@@ -6,6 +6,7 @@ class Hash
# # => { a: 2, b: 4, c: 6 }
def transform_values
return enum_for(:transform_values) unless block_given?
+ return {} if empty?
result = self.class.new
each do |key, value|
result[key] = yield(value)