[ruby-dev:50027] [Ruby trunk Bug#13344] Improve performance of Array#sort with block

From: watson1978@...
Date: 2017-03-21 03:00:05 UTC
List: ruby-dev #50027
Issue #13344 has been reported by watson1978 (Shizuo Fujita).

----------------------------------------
Bug #13344: Improve performance of Array#sort with block
https://bugs.ruby-lang.org/issues/13344

* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Array#sort with block will be ~10% faster.
Seems that a performance was reduced at
https://github.com/ruby/ruby/blob/976becf7eb18aa1592c703ac4d86a2cf9dfa701e/vm_eval.c#L1042-L1046
So by this patch, a small argument will be given directly into rb_yield_values2()

### Before
~~~
       user     system      total        real
   0.860000   0.000000   0.860000 (  0.869366)
~~~

### After
~~~
       user     system      total        real
   0.790000   0.000000   0.790000 (  0.791408)
~~~

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

Benchmark.bmbm do |x|

  ary = []
  1000.times { |i| ary << Random.rand(1000) }

  x.report do

    1000.times do
      ary.sort{ |a,b| a<=>b}
    end

  end

end
~~~

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



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

In This Thread

Prev Next