[jboss-user] [JBoss Microcontainer Development] - JBoss Reflect Performance Javassist vs Introspection

Kabir Khan do-not-reply at jboss.com
Fri May 21 05:29:53 EDT 2010


Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion

"JBoss Reflect Performance Javassist vs Introspection"

To view the discussion, visit: http://community.jboss.org/message/544167#544167

--------------------------------------------------------------
> Kabir Khan wrote:
> 
> Another observation is that quite a few calls to JavassistMethodInfo.getParameterTypes() are only interested in the length of the parameters and the names of the parameter types, so it might be an idea to return an array of "lazy" type infos which only know the name and the declaring typeinfo. I can be found out easily from the raw method signature (I am already passing the SignatureKey into JavassistMethodInfo and using that in its equals() method to avoid having to load parameters there). Once something more advanced is called, then that could obtain the real typeinfo and delegate to that. I'm not 100% sure yet if this is what I want to do.
I've looked more into this and will try out "lazy" type infos. When constructing the BeanInfos, it goes through and calls MethodInfo.getReturnType() and MethodInfo.getParameterTypes(). These calls are really heavy, and at least for this use-case we don't care about anything apart from the name. Behind the scenes, what happens for each parameter is: 

a) It hits the classpool to load the CtClass
b) When creating the type info it needs to check if the class is an enum or annotation, the first time you call anything apart from CtClass.getName() it needs to load the underlying ClassFile. This is slow, but initialises the CtClass for future use. 

a) and b) seem to take about the same time, although b) probably varies with class size. I don't think we can do much about b) apart from trying to avoid it at all costs.

Another observation in favour of optimizing the classpools further is needing to do this in JavassistTypeInfoFactory.get() (pseudocode)

public TypeInfo get(ClassLoader cl, String name){
 
    Cache cache = getCacheForLoader(cl);
    TypeInfo info = cache.get(name);
    if (info != null)
       return info;
 
    //The passed in classloader is not necessarily the one where the class lives,
    //so we need to hit the pool to find out where it comes from
    ClassPool pool = getPoolForLoader(cl);
    CtClass clazz = pool.get(name);
 
    if (clazz.getClassPool().getClassLoader() != cl)
    {
       cl = clazz.getClassPool().getClassLoader(); 
       cache = getCacheForLoader(cl);
       info = cache.get(name);
       if (info != null)
          return info;
    }
 
    info = instantiate(clazz);
    cache.cache(info);
 
   return info;
}


We need to query the pool to figure out the correct classloader

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/544167#544167]

Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100521/e6081ae9/attachment.html 


More information about the jboss-user mailing list