Issue #13343 has been updated by watson1978 (Shizuo Fujita).


I followed the behavior of Array's methods such as

~~~
VALUE
rb_ary_sort(VALUE ary)
{
    ary = rb_ary_dup(ary);
~~~

It does not check whether initialize_dup/initialize_copy were overridden.


----------------------------------------
Bug #13343: Improve Hash#merge performance
https://bugs.ruby-lang.org/issues/13343#change-63850

* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Hash#merge will be faster around 60%.

### Before
~~~
                 user     system      total        real
Hash#merge   0.160000   0.020000   0.180000 (  0.182357)
~~~

### After
~~~
                 user     system      total        real
Hash#merge   0.110000   0.010000   0.120000 (  0.114404)
~~~

### Test code
~~~
require 'benchmark'

Benchmark.bmbm do |x|
  hash1 = {}
  100.times { |i| hash1[i.to_s] = i }
  hash2 = {}
  100.times { |i| hash2[(i*2).to_s] = i*2 }

  x.report "Hash#merge" do
    10000.times do
      hash1.merge(hash2)
    end
  end
end
~~~

### Patch
The patch is in https://github.com/ruby/ruby/pull/1533



-- 
https://bugs.ruby-lang.org/