Announcement Announcement Module
Collapse
No announcement yet.
Byte Code Generation vs. Reflection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Byte Code Generation vs. Reflection

    Hi everyone!

    I have question regarding the performance of getting data from an Object by using reflection or by generating a proxy object (when this solution is appropiate) with the necessary code for doing that.

    Do you have any idea about which solution seams to be mode perfomant?

    Thank you very much!

    Cristian.

  • #2
    It depends on your exact use case. Theoretically the JDK proxies *can* be faster because they have VM level support however in practise this seems not be to *absolute* case because of limitations in the API.

    In a like for like call on a method that has advice applied to it you will not notice so much difference on newer VMs. We do make some optimisations in the bytecode proxies for this case, but in general they seem not to be noticeable right now.

    On a like for like call on a method that has no advice applied to it you will almost certainly find that a bytecode proxy is faster, because we can skip a whole set of instructions using the bytecode mechanism. It is important to understand that this is *not* a limitation of the JVM proxying mechanism but rather a restriction of the API used to generate those proxies. A better JDK proxy API would allow for much faster proxies.

    In most cases you will find that JDK proxies are much more memory efficient and they don't encounter issues with final methods like when class proxying.

    The general rule I apply right now is to use JDK proxies by default. If I have an object that is a singleton (thus rendering memory considerations for the proxy irrelevant) and it has some critical unadvised methods then I will use class proxying.

    In 1.4 or 1.5 I will have finished the work on the new bytecode proxy architecture which should allow for much more control over the code that is generated and may result in bytecode proxies that are faster.

    Rob

    Comment


    • #3
      Thank you very much for your answer Rob!

      I must say that my question was not sufficient clear, and beside that I'm quite new in these aspects as ones regarding byte code generation at runtime and all the proxy terminology.

      The exact use case is within a webframework I'm trying to build.
      Here I would like to have a pair of one pure xhtml page and a java class with no dependency to the framework. For the moment the conection between these to elements is made through ognl expression (like in Tapestry) by a behind the scene framework class. My intention is to generate the class that would make the connection not to ognl expressions but directly by calling the real code resulting from those expressions and so avoiding all the reflection process. This generated class would loaded in memory by jvm for future reuse so the generation will be done only once for each page.

      I now think this would be faster.

      Anyway, thank you a lot for your answer. It was really helpful!

      Regards!

      Cristian.

      Comment

      Working...
      X