Project

General

Profile

Feature #15010

Updated by chopraanmol1 (Anmol Chopra) over 5 years ago

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.340000     0.408000     0.000000     0.340000 0.408000 (    0.337035) 0.405603) 
 rest_method                     0.964000          0.992000     0.000000     0.964000 0.992000 (    0.964660) 0.992706) 
 lead_method                     0.976000          1.000000     0.000000     0.976000 1.000000 (    0.976011) 0.999311) 
 post_method                     2.424000          2.464000     0.000000     2.424000 2.464000 (    2.421732) 2.464712) 
 lead_post_method                    1.800000     0.000000     1.800000 (    1.799500) 1.800882) 
 rest_with_named_parameter       2.040000     0.000000     2.040000 (    2.040323) 
 lead_proc underflow_args        1.224000     0.000000     1.224000 (    1.225237) 
 opt_post_proc overflow_args     1.056000     0.000000     1.056000 (    1.057402) 
 ~~~ 

 modified 
 ~~~ 
                                   
                        user       system        total          real 
 benchmark_method                0.336000     0.400000     0.000000     0.336000 0.400000 (    0.336911) 0.401134) 
 rest_method                     0.708000          0.740000     0.000000     0.708000 0.740000 (    0.706142) 0.741038) 
 lead_method                     0.720000          0.748000     0.000000     0.720000 0.748000 (    0.717971) 0.746265) 
 post_method                     1.896000          1.992000     0.000000     1.896000 1.992000 (    1.894426) 1.992200) 
 lead_post_method                1.560000     0.000000 1.632000     1.560000 (    1.560495) 
 rest_with_named_parameter       1.464000     0.000000     1.464000 1.632000 (    1.467313) 
 lead_proc underflow_args        0.864000     0.000000     0.864000 (    0.863980) 
 opt_post_proc overflow_args     0.772000     0.000000     0.772000 (    0.770364) 1.631994) 
 ~~~

Back