提交 3e408a26 编写于 作者: S Sean Griffin

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
上级 58750422
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册