I've started to make changes to the call path for compiled code along
the lines of my earlier post. Basically I committed two changes this
evening:
1. Compiled code now retrieves a Dispatcher directly from the metaclass
and calls against that.
2. Dispatcher now retrieves a DynamicMethod instance directly and
invokes against that.
The basic idea is generating a little bit more code to eliminate
generated code all along the way. The result is that unique code calls
unique code calls unique code, and HotSpot can very quickly discover how
to inline most of the calls.
Future improvements to this will be breaking up dispatcher to act as an
adapter for separate methods, so all methods can be inlined individually
rather than inlining the whole dispatch switch. Also, CompiledMethod
must generate the actual call() method rather than a polymorphic
subclass method, and DefaultMethod must actually replace itself in the
method table after JITing, to allow future calls to go straight into the
custom code.
These two changes will be required to see substantial improvements to
method-to-method calls, but the changes thusfar give another serious
boost to STI invocations. Witness:
before:
Test STI: 100k loops accessing a fixnum var and calling to_i 100 times
1.217000 0.000000 1.217000 ( 1.217000)
0.390000 0.000000 0.390000 ( 0.391000)
0.395000 0.000000 0.395000 ( 0.395000)
0.330000 0.000000 0.330000 ( 0.330000)
0.324000 0.000000 0.324000 ( 0.325000)
0.324000 0.000000 0.324000 ( 0.325000)
0.324000 0.000000 0.324000 ( 0.325000)
0.323000 0.000000 0.323000 ( 0.323000)
0.323000 0.000000 0.323000 ( 0.323000)
0.324000 0.000000 0.324000 ( 0.324000)
Test non-STI: 100k loops accessing an Array var and calling to_a 100 times
1.389000 0.000000 1.389000 ( 1.389000)
0.607000 0.000000 0.607000 ( 0.607000)
0.577000 0.000000 0.577000 ( 0.577000)
0.529000 0.000000 0.529000 ( 0.529000)
0.525000 0.000000 0.525000 ( 0.525000)
0.515000 0.000000 0.515000 ( 0.515000)
0.506000 0.000000 0.506000 ( 0.507000)
0.507000 0.000000 0.507000 ( 0.507000)
0.515000 0.000000 0.515000 ( 0.515000)
0.506000 0.000000 0.506000 ( 0.506000)
~/NetBeansProjects/jruby $ jruby -J-server
test/bench/bench_fib_recursive.rb
1.577000 0.000000 1.577000 ( 1.578000)
1.227000 0.000000 1.227000 ( 1.228000)
1.201000 0.000000 1.201000 ( 1.203000)
1.197000 0.000000 1.197000 ( 1.197000)
1.186000 0.000000 1.186000 ( 1.186000)
1.191000 0.000000 1.191000 ( 1.191000)
1.182000 0.000000 1.182000 ( 1.182000)
1.188000 0.000000 1.188000 ( 1.188000)
after:
Test STI: 100k loops accessing a fixnum var and calling to_i 100 times
1.218000 0.000000 1.218000 ( 1.218000)
0.259000 0.000000 0.259000 ( 0.259000)
0.250000 0.000000 0.250000 ( 0.250000)
0.247000 0.000000 0.247000 ( 0.247000)
0.201000 0.000000 0.201000 ( 0.202000)
0.199000 0.000000 0.199000 ( 0.199000)
0.199000 0.000000 0.199000 ( 0.199000)
0.198000 0.000000 0.198000 ( 0.198000)
0.199000 0.000000 0.199000 ( 0.199000)
0.203000 0.000000 0.203000 ( 0.203000)
Test non-STI: 100k loops accessing an Array var and calling to_a 100 times
1.255000 0.000000 1.255000 ( 1.256000)
0.255000 0.000000 0.255000 ( 0.255000)
0.261000 0.000000 0.261000 ( 0.262000)
0.265000 0.000000 0.265000 ( 0.265000)
0.200000 0.000000 0.200000 ( 0.200000)
0.196000 0.000000 0.196000 ( 0.196000)
0.199000 0.000000 0.199000 ( 0.199000)
0.196000 0.000000 0.196000 ( 0.196000)
0.196000 0.000000 0.196000 ( 0.197000)
0.197000 0.000000 0.197000 ( 0.197000)
~/NetBeansProjects/jruby $ jruby -J-server
test/bench/bench_fib_recursive.rb
1.307000 0.000000 1.307000 ( 1.307000)
1.083000 0.000000 1.083000 ( 1.083000)
1.035000 0.000000 1.035000 ( 1.035000)
1.059000 0.000000 1.059000 ( 1.059000)
1.033000 0.000000 1.033000 ( 1.033000)
1.042000 0.000000 1.042000 ( 1.042000)
1.018000 0.000000 1.018000 ( 1.018000)
1.028000 0.000000 1.028000 ( 1.028000)
More improvements will be coming, but I'm going to back off for the
moment and see about a redesign/refactoring of the existing codegen
stuff. It's getting a bit too difficult to follow.
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email