Issue #15010 has been updated by chopraanmol1 (Anmol Chopra).


mame (Yusuke Endoh) wrote:
> Some other functions in vm_args.c also use rb_ary_dup.  There may be more room to optimize.

Yes, it can be further optimized for keyword argument and argument setup for the block. I'll modify the patch in a day or two. 

----------------------------------------
Feature #15010: Reduce allocation for rest parameters
https://bugs.ruby-lang.org/issues/15010#change-73620

* Author: chopraanmol1 (Anmol Chopra)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently multiple arrays are allocated while making a call to method with rest parameter.

E.g.
~~~
def rest_method(*args) #-> This will create 2 arrays
end

def post_method(*args,last) #-> This will create 3 arrays
end
~~~

Applying following set of changes will reduce creation of array to 1

https://github.com/ruby/ruby/pull/1935

Benchmark Result:

trunk
~~~
                       user     system      total        real
benchmark_method   0.408000   0.000000   0.408000 (  0.405603)
rest_method        0.992000   0.000000   0.992000 (  0.992706)
lead_method        1.000000   0.000000   1.000000 (  0.999311)
post_method        2.464000   0.000000   2.464000 (  2.464712)
lead_post_method   1.800000   0.000000   1.800000 (  1.800882)
~~~

modified
~~~
                       user     system      total        real
benchmark_method   0.400000   0.000000   0.400000 (  0.401134)
rest_method        0.740000   0.000000   0.740000 (  0.741038)
lead_method        0.748000   0.000000   0.748000 (  0.746265)
post_method        1.992000   0.000000   1.992000 (  1.992200)
lead_post_method   1.632000   0.000000   1.632000 (  1.631994)
~~~

---Files--------------------------------
bench_method_arg.rb (774 Bytes)
improve_rest_parameters_setup.patch (1.76 KB)


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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>