From a24912cb1d34912a16aa27d952beff825e558f1f Mon Sep 17 00:00:00 2001
From: Michael Lovitt <michael@lovitt.net>
Date: Thu, 18 May 2017 15:38:30 -0500
Subject: 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.
---
 activerecord/lib/active_record/attribute_set.rb | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

(limited to 'activerecord/lib')

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(_)
-- 
cgit v1.2.3