aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMichael Lovitt <michael@lovitt.net>2017-05-18 15:38:30 -0500
committerMichael Lovitt <michael@lovitt.net>2017-05-24 17:26:20 -0500
commita24912cb1d34912a16aa27d952beff825e558f1f (patch)
treec860c8d40137e75b3401db06bcf955a79c7a5bad /activerecord/lib
parent0fa9084a18d1d9c4765c526b740f3f0b550055ca (diff)
downloadrails-a24912cb1d34912a16aa27d952beff825e558f1f.tar.gz
rails-a24912cb1d34912a16aa27d952beff825e558f1f.tar.bz2
rails-a24912cb1d34912a16aa27d952beff825e558f1f.zip
Performance optimization for AttributeSet#deep_dup
Skip the call to #dup, since it does a shallow copy of attributes, which is wasted effort, since #deep_dup then replaces that shallow copy with a #deep_dup of the given attributes. This change addresses slowness in ActiveRecord initialization introduced starting in Rails 5.0.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_set.rb4
1 files changed, 1 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb
index 66b278219a..abe8e14f26 100644
--- a/activerecord/lib/active_record/attribute_set.rb
+++ b/activerecord/lib/active_record/attribute_set.rb
@@ -64,9 +64,7 @@ module ActiveRecord
end
def deep_dup
- dup.tap do |copy|
- copy.instance_variable_set(:@attributes, attributes.deep_dup)
- end
+ self.class.new(attributes.deep_dup)
end
def initialize_dup(_)