Announcement Announcement Module
Collapse
No announcement yet.
meta-data driven vs XML configuration proxying Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • meta-data driven vs XML configuration proxying

    Hello.

    I've new to Spring framework and really impressed. Me an my team are trying to replace the Stateless EJB layer from our application to Spring.
    My question is about the differences between the doing transaction demarcation through meta-data and through XML configuration - I would like to hear what are the oppinions on these approaches and which performs better ?

    I know that everyone has his/her own way but considering that I'm new to this framework I'd like some advice to make my own oppinion.I looked over the internet but I couldn't find any info about the performance of Commons Attribute (C-A) - how fast is to extract the information from the source then evaluating a regular expression on the method name (XML configuration)?

    I personally like the XML approach for serveral reasons (pls comment):
    1. you don't need an additional step in compiling. Indeed is not that complicated but the source code is changed with Commons Attribute which means debugging can be a problem - you have additional code there.
    2. I have no evidence so pls comment on this one but I suppose evaluating a regex is faster then checking an attribute.
    3. Xdoclet tags can help in providing source-code level tags which can generate XML configuration files.
    4. the transaction configuration can be changed at runtime without any need of compiling. I have never had this issue but still it offers more decoupling.

    I realize I might be still biased towards Xdoclet use even though this might not be the case so you are more then welcome to give feedback.

    Thanks.

  • #2
    Costin,

    I can't comment too much on the performance of looking up an attribute, but it can't be that much. To see what I mean, take a look at the source code that is generated by Commons Attributes for your annotated classes.

    That said, I prefer the XML-based approach purely because it allows me to change the behaviour at runtime and it keeps all my config in the same place.

    Also, I wouldn't worry too much about the performance of one method vs the other since Spring caches as much of the information as possible so you will only notice a difference at startup time.

    Rob

    Comment


    • #3
      Thanks.

      I'll take a look at the sources and see if I find anything on the C-A lists related to performance.

      I'll post back to this thread if I find anything.

      Comment


      • #4
        After looking closely at the C-A documentation I found an interesting note here.

        Performance Notes

        The process of loading attributes for a class is a (relatively) time-consuming process, as it involves some dynamic linking in the form of inheritable attributes, a lot of reflection and so on. However, once loaded the attributes are cached, so repeated access to them are fast. But despite this the process of finding one attribute of a given type or such operations does involve some iteration of HashSets that runs in linear time in the number of attributes associated with the program element, and you should avoid accessing attributes in your innermost loops if you can avoid it. For example, instead of:


        Class myClass = ...;
        for (int i = 0; i < 10000; i++) {
        if (Attributes.hasAttributeType (myClass, MyAttribute.class)) {
        doThis(myClass);
        } else {
        doThat(myClass);
        }
        }


        do:


        Class myClass = ...;
        boolean shouldDoThis = Attributes.hasAttributeType (myClass, MyAttribute.class);
        for (int i = 0; i < 10000; i++) {
        if (shouldDoThis) {
        doThis(myClass);
        } else {
        doThat(myClass);
        }
        }


        if the loop should run at maximum speed.
        I also send an email on the mailing list - in case I'll receive a relevant answer I'll post it here (and maybe turn this topic into a wiki page ).

        Comment


        • #5
          Costin,

          I wouldn't worry that much about the performance since reading of attributes is generally a startup only task. Plus subsequent reads of attributes are served from the cache so they will be much faster.

          Rob

          Comment

          Working...
          X