8 Replies Latest reply on Oct 26, 2007 9:36 AM by Dmitriy Lapko

    Let's use component scope before lookupInStatefulContexts

    Dmitriy Lapko Newbie

      One of the key methods of Seam in class Component is:

      public static Object getInstance(String name, boolean create)
       {
       Object result = Contexts.lookupInStatefulContexts(name);
       result = getInstance(name, create, result);
       return result;
       }
      


      Method lookupInStatefulContexts checks all possible scopes for an instance of a requested component. But as for me, usually a scope for a component is defined and I don't understand, why can't we use this information before scanning of all contexts.

      If I marked my component by annotation @Scope, and defined its scope to Session, wouldn't it be faster not to check method, event, page and conversation scopes before getting it from session? Searching in method, event and page contexts is fast, just hashmap searching, but for conversation scope it is much longer and depends on component realization.

      Why do I ask - because in my application there are more session scoped components then conversation scoped. And for them method ServerConversationContext.isPerNestedConversation is called anyway and it takes more then 1% of CPU time in all application, because it iterates among all methods in component trying to find annotation PerNestedConversation (I profiled it with JProfiler).

      So, it just a question for discussion - what is a key reason not to use

      Component component = Component.forName(name);
      component.getScope();


      in method Contexts.lookupInStatefulContexts and search only in this scope or untill this scope?