Fast Reflection
I replaced some critical reflective method and constructor invocations in one of my frameworks with cglib's optimized counterparts and saw about a 40% overall performance boost on Java 1.5. I only replaced the invocations, not the lookups, etc. I suspect cglib elides the security checks among other things, but I haven't dug too deeply.
10 Comments:
Bob, java relflection supposed to generate class after something like 15 invocations. Haven you take that into your measurements?
Yeah, I iterated about a million times.
Nice
Try it with setAccessible(true), it skips the security checks and in some situations may get you close to compiled speed.
This is a tip from a friend, and we've had mixed results with it. But worth trying.
I did that, too.
It's true, there aren't any security checks. Also, don't go crazy using it across the board or you'll exhaust your permgen memory. Glad it's still useful though... I didn't think this stuff would find much use after 1.5.
Hmmmm... we're already pushing our permgen pretty far. I should make this switchable.
If you turn off a reflection check with call of setAccessible method, you will have almost the same performance as CGLib's.
It would be very strange if Sun's implementation is slower than one that is created by third party.
i wish Guice did not carry the cglib stuff within. it makes the jar size pretty big.
Chris Nockleberg is helping us trim that down.
Post a Comment
<< Home