1

I have bean util library and we cache Method/Fields of properties, of course. Reading and writing goes via reflection.

There is an idea to skip reflection and for each method/field to bytecode-generate a simple object that directly calls the target. For example, if we have setFoo(String s) method, we would call a set(String s) method of this generated class that internally calls setFoo(). Again, we are replacing the reflection call with the runtime generated direct call.

I know Java does similar thing with GeneratedMethodAccessor. But it's cache may be limited by JVM argument.

Does anyone know if it make sense to roll-on my implementation, considering the performance? On one hand, it sounds fine, but on other, there are many new classes that will be created - and fill perm gen space.

Any experience on this subject?

igr
  • 10,199
  • 13
  • 65
  • 111

1 Answers1

1

You are trying to re-invent cglib's FastMethod
In fact, Reflection is not slower at all. See https://stackoverflow.com/a/23580143/3448419

Reflection can do more than 50,000,000 invocations per second. It is unlikely to be a bottleneck.

Community
  • 1
  • 1
apangin
  • 92,924
  • 10
  • 193
  • 247
  • Thank you for the link. My tests were with similar results - no statistically significant difference. Thank you! – igr Jul 31 '14 at 13:36