Interpreted case/when is much slower than MRI
---------------------------------------------

                 Key: JRUBY-2984
                 URL: http://jira.codehaus.org/browse/JRUBY-2984
             Project: JRuby
          Issue Type: Bug
          Components: Performance
    Affects Versions: JRuby 1.1.4
            Reporter: Charles Oliver Nutter
             Fix For: JRuby 1.1.5


Ouch...the interpreter seems to have *serious* performance issues when it comes 
to case/when statements:

Note this is only numbers for the 10-when case in this benchmark
{noformat}
➔ jruby --server -X-C bench_case.rb 
                                              user     system      total        
real
1m x5 cases with 10 whens                16.053000   0.000000  16.053000 ( 
16.053354)
                                              user     system      total        
real
1m x5 cases with 10 whens                24.339000   0.000000  24.339000 ( 
24.338982)
                                              user     system      total        
real
1m x5 cases with 10 whens                26.326000   0.000000  26.326000 ( 
26.326204)
                                              user     system      total        
real
1m x5 cases with 10 whens                28.603000   0.000000  28.603000 ( 
28.602653)
                                              user     system      total        
real
1m x5 cases with 10 whens                32.623000   0.000000  32.623000 ( 
32.623010)
~/NetBeansProjects/jruby ➔ /opt/local/bin/ruby bench_case.rb 
                                              user     system      total        
real
1m x5 cases with 10 whens                 9.070000   0.090000   9.160000 (  
9.344732)
                                              user     system      total        
real
1m x5 cases with 10 whens                 9.080000   0.090000   9.170000 (  
9.595736)
                                              user     system      total        
real
1m x5 cases with 10 whens                10.880000   0.140000  11.020000 ( 
11.791109)
                                              user     system      total        
real
1m x5 cases with 10 whens                11.310000   0.130000  11.440000 ( 
12.018376)
                                              user     system      total        
real
1m x5 cases with 10 whens                10.100000   0.120000  10.220000 ( 
10.626142)
{noformat}

Note that in this case, where all the cases are fixnums, Ruby 1.9 is performing 
a direct jump. Experimental code for doing the same in JRuby produces an 
extremely large boost in performance:

{noformat}
Ruby 1.9:
~/NetBeansProjects/jruby ➔ ../ruby1.9/ruby -I ../ruby1.9/lib 
bench_case.rb 
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.400000   0.000000   0.400000 (  
0.415587)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.400000   0.010000   0.410000 (  
0.409474)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.400000   0.000000   0.400000 (  
0.410365)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.410000   0.000000   0.410000 (  
0.414840)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.400000   0.000000   0.400000 (  
0.409613)

JRuby:
~/NetBeansProjects/jruby ➔ jruby --server bench_case.rb 
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.430000   0.000000   0.430000 (  
0.429635)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.301000   0.000000   0.301000 (  
0.300480)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.235000   0.000000   0.235000 (  
0.235214)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.198000   0.000000   0.198000 (  
0.198281)
                                              user     system      total        
real
1m x5 cases with 10 whens                 0.200000   0.000000   0.200000 (  
0.199393)
{noformat}

Compiled performance, even without the switch optimization, is substantially 
better than the interpreter, but nowhere near 1.9 performance:

{noformat}
➔ ../jruby-1_1_3/bin/jruby --server bench_case.rb 
                                              user     system      total        
real
1m x5 cases with 10 whens                 7.026000   0.000000   7.026000 (  
7.026314)
                                              user     system      total        
real
1m x5 cases with 10 whens                 4.693000   0.000000   4.693000 (  
4.692950)
                                              user     system      total        
real
1m x5 cases with 10 whens                 4.647000   0.000000   4.647000 (  
4.646249)
                                              user     system      total        
real
1m x5 cases with 10 whens                 4.674000   0.000000   4.674000 (  
4.674111)
                                              user     system      total        
real
1m x5 cases with 10 whens                 4.603000   0.000000   4.603000 (  
4.603245)
{noformat}

We should also include benchmarks for all literals, to see where 1.9 is doing 
optimizations we can mimic.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to