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.
Bob, java relflection supposed to generate class after something like 15 invocations. Haven you take that into your measurements?
ReplyDeleteYeah, I iterated about a million times.
ReplyDeleteNice
ReplyDeleteTry it with setAccessible(true), it skips the security checks and in some situations may get you close to compiled speed.
ReplyDeleteThis is a tip from a friend, and we've had mixed results with it. But worth trying.
I did that, too.
ReplyDeleteIt'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.
ReplyDeleteHmmmm... we're already pushing our permgen pretty far. I should make this switchable.
ReplyDeleteIf you turn off a reflection check with call of setAccessible method, you will have almost the same performance as CGLib's.
ReplyDeleteIt 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.
ReplyDeleteChris Nockleberg is helping us trim that down.
ReplyDelete