[E-Lang] Reflection invoke() timing measurement

Mark S. Miller markm@caplet.com
Thu, 19 Jul 2001 09:11:35 -0700


At 05:54 AM Thursday 7/19/01, Jonathan S. Shapiro wrote:
>Pardon an ignorant and off-topic question. I don't know enough about Java
>reflection to understand this. Is there any inherent reason why reflective
>invoke should be less efficient than conventional invoke? I suspect there is
>a marginal indirection somewhere, but I cannot think of anything else that's
>substantive.

Neither ignorant nor off-topic, so I deny my pardon!

I believe you are essentially correct.  The additional difference comes from 
the lack of statically analyzable information at the call site, preventing 
or impeding various operations.  To those familiar with Smalltalk 
implementations, there's no reason for "invoke()" to perform worse than 
"perform:".  In fact, invoke() should be able to invoke faster, as there's 
that first class Message object available for hanging internal optimization 
info on (such as a call-site cache).

Given this comparison, it's especially surprising that such a large 
difference still remains (even after the substantial improvements by 
JDK1.4), since Hotspot descends from the Smalltalk implementation tradition.


        Cheers,
        --MarkM