<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    JBoss Reflect Performance Javassist vs Introspection
</h3>
<span style="margin-bottom: 10px;">
    reply from <a href="http://community.jboss.org/people/kabir.khan%40jboss.com">Kabir Khan</a> in <i>JBoss Microcontainer Development</i> - <a href="http://community.jboss.org/message/543921#543921">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Although too early to say yet, it looks like the classpools are a bottleneck. I have started caching things a bit more and that is speeding things up somewhat. For example calling CtBehavior.getParameterTypes() is slow since it does not cache the parameter types, instead for every call to this it parses the method signature and then hits the classpools for every class. I am attempting to avoid that as much as possible.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Once I am done with caching things as much as possible, we'll see if the classpools are still a bottleneck since there will be a lot less calls. If they are, I have an idea for how to change them into something simpler, but just want to jot it down so Flavia can take a look and see if she thinks it is a good idea or if I have missed something.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The idea is quite simple, rather than managing the domains and pools and essentially recreating what the classloaders do, it might make sense to delegate everything to the classloaders. If we had a method like this, as I discussed with Ales (let's say it goes in the ClassLoading class, although where is up to Ales):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">ClassLoader getClassLoaderForClass(ClassLoader initiating, String classname);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And we have a map of classpools by classloader in the classpool registry. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Then I think our "dumb" class pool would not need much more than this - it has a null parent</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>class</b></font> DumbClassPool <font color="navy"><b>extends</b></font> ClassPool<font color="navy">{</font>
&#160;
&#160;&#160;&#160; WeakReference&lt;ClassLoader&gt; cl;
&#160;&#160;&#160; ClassPoolRepository repo;
&#160;
&#160;&#160;&#160; DumbClassPool(ClassLoader cl, ClassPoolRepository repo)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; this.cl = <font color="navy"><b>new</b></font> WeakReference&lt;ClassLoader&gt;(cl);
&#160;&#160;&#160;&#160;&#160; this.repo = repo;
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;
&#160;&#160;&#160; CtClass get(String classname)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//Check cache first, if not found then do the rest</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; CtClass clazz = super.get0(classname);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (clazz != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> clazz;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; String real = adjustForArraysAndPrimitives(classname);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ClassLoader loader = ClassLoading.getClassLoaderForClass(cl.get(), real);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ClassPool pool = repo.registerClassLoader(loader);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (pool != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; clazz = pool.getOrNull(classname); <font color="darkgreen">//new method from Chiba that does not throw NFE, but behaves like get()</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (clazz != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//cache class</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>else</b></font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> NotFoundException
&#160;&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'd obviously be extending ScopedClassPool or whatever is needed in AOP and other places. It would also have some knowledge of the domain and get notified when loaders get added/removed to the domain so the caches in the pools can be invalidated. There will probably be a bit more to it than this, but this is the basic idea.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre ___default_attr="java" jivemacro="code"><p><span style="white-space: pre; font-family: monospace, helvetica, sans-serif; "><br/></span></p></pre></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/543921#543921">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Microcontainer Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>