6 Replies Latest reply on Sep 28, 2007 10:26 PM by mgrouch

    Small Seam code optimization suggestion

      Hi,

      I was profiling my web application and I took note of some little modifications that could be done in the Seam code that in my opinion would improve performance a little bit. Mind you this is just a little bit but I'll take every milliseconds I can get! I don't mean to critisize or anything. They are just suggestions.

      #1:
      During the execution of one JSF request, I noticed a lot of calls to the org.jboss.seam.Component.hasAnnotation method. Couldn't this information be cached somewhere? I know the reflection API is quite fast but in this particular context, couldn't all the "metadata" of a component be stored as class members of the Component class? I know some if already is but I found something that could be added. In the org.jboss.seam.contexts.ServerConversationContext class, the following method seems to be called hundreds of times per request:

      private boolean isPerNestedConversation(String name)
      {
       Component component = Component.forName(name);
       return (component != null) && component.beanClassHasAnnotation(PerNestedConversation.class);
       }
      


      Could't a "perNestedConversation" class member be added on the org.jboss.seam.Component class and initialized when initializing the component instead of looking for the annotation every time? This is just one example. I haven't looked everywhere where the org.jboss.seam.Component.hasAnnotation is called but perhaps similar optimizations could be done elsewhere.

      #2:
      In my particular project, I disabled Seam's transaction management by setting the "transaction-management-enabled" attribute to "false" on the "core:init" element in a components.xml file. Basically, I don't want Seam to do anything as far as dabatase transaction and entites are concerned. In the org.jboss.seam.Component.hasAnnotation.initDefaultInterceptors method, certain interceptors that pertain to transaction management are still added. Again, this is a small detail but the ones that bug me are the RollbackInterceptor and the ManagedEntityIdentityInterceptor. Well, maybe they're not necessarily related to transaction management but anyways, both of them wind up doing lookups in the JNDI tree for a transaction (through various methods of the org.jboss.seam.transaction.Transaction class) and I don't have any set. I'd like to get rid of these unnecessary JNDI lookups. Perhaps adding a check for org.jboss.seam.core.Init.instance().isTransactionManagementEnabled() in the org.jboss.seam.Component.hasAnnotation.initDefaultInterceptors method before adding those 2 interceptors would do the trick?

      That's it for now. Again, I know it's not much but a couple of milliseconds here and there amount to something in the end.

      Thanks.