Colin Fleming wrote:
> On 31/01/07, Niklas Therning <[EMAIL PROTECTED]> wrote:
>> Well, reflection is of course a lot slower than direct method
>> invocations.
>
> <snip>
>
>> Anyhow I would still want to optimize these parts of mina-sm using byte
>> code generation and, if possible, eliminate the need for reflection
>> entirely.
>
> This might be interesting to you, if you haven't seen it:
> http://www.sixlegs.com/blog/java/cglib-fastclass.html
>
That looks really cool! I just replicated this test with Sun's Java6
(build 1.6.0-b105 under Ubuntu) and it seems like java.lang.reflect is
catching up but CGLIB (2.1_3) still seems faster:

Using java -client:
Reflection: 324 ms (3.70)
CGLIB FastMethod: 238 ms (2.45)
CGLIB InvokeByIndex: 236 ms (2.42)
Direct: 69 ms

Using java -server:
Reflection: 237 ms (10.29)
CGLIB FastMethod: 193 ms (8.19)
CGLIB InvokeByIndex: 181 ms (7.62)
Direct: 21 ms

One thing I noticed is that when I lookup the method in every iteration
both CGLIB and reflection performs terribly bad which suggests that if
possible one should always try to hold on to the Method, FastMethod or
index if possible and only look it up the first time it's used.

Here are the same figures using Sun's Java5 (build 1.5.0_08-b03 under
Ubuntu):

Using java -client:
Reflection: 493 ms (5.40)
CGLIB FastMethod: 269 ms (2.49)
CGLIB InvokeByIndex: 269 ms (2.49)
Direct: 77 ms

Using java -server:
Reflection: 230 ms (2.07)
CGLIB FastMethod: 225 ms (2.0)
CGLIB InvokeByIndex: 227 ms (2.0)
Direct: 75 ms

Wow! Seems like Sun managed to speed up direct method invocations a lot
for the Server VM in Java 1.6.

-- 
Niklas Therning
www.spamdrain.net

Reply via email to