Hi Guys,<div><br></div><div>First of all, congrats for the 5.3 release!</div><div><br></div><div>I was having a look at the recent improvements done to rules compilation, mentioned <a href="http://docs.jboss.org/drools/release/5.3.0.Final/droolsjbpm-introduction-docs/html_single/index.html#d0e47">here</a>, and I unfortunately couldn&#39;t really realize a 3 times faster compilation :(</div>
<div><br></div><div>After some profiling, my problem seems to come from some unsuccessful attempts to getResourceAsStream done at org.drools.commons.jci.compilers.EclipseJavaCompiler. Basically on line 218, to be able to know if something is a type or not, it will get a supposedly class name and try to load it, if it cannot be loaded then it will infer that what it thought was a class was actually a package.  </div>
<div><br></div><div>Here goes a call stack, to give some context. In this particular case, the string parameter was &quot;<a href="http://com.sample.org">com.sample.org</a>&quot;, thus not a type.</div>







<div><br></div><div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
EclipseJavaCompiler$2.findType(String) line: 220<span class="Apple-tab-span" style="white-space:pre">        <br></span>EclipseJavaCompiler$2.findType(char[], char[][]) line: 215<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>LookupEnvironment.askForType(PackageBinding, char[]) line: 127<span class="Apple-tab-span" style="white-space:pre">        <br></span>PackageBinding.getTypeOrPackage(char[]) line: 183<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>MethodScope(Scope).getTypeOrPackage(char[], int, boolean) line: 2592<span class="Apple-tab-span" style="white-space:pre">        <br></span>MethodScope(Scope).getPackage(char[][]) line: 2266<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>QualifiedTypeReference.getTypeBinding(Scope) line: 69<span class="Apple-tab-span" style="white-space:pre">        <br></span>QualifiedTypeReference(TypeReference).internalResolveType(Scope) line: 130<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>QualifiedTypeReference(TypeReference).resolveType(BlockScope, boolean) line: 197<span class="Apple-tab-span" style="white-space:pre">        <br></span>SourceTypeBinding.resolveTypesFor(MethodBinding) line: 1370<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>SourceTypeBinding.methods() line: 1090<span class="Apple-tab-span" style="white-space:pre">        <br></span>SourceTypeBinding.faultInTypesForFieldsAndMethods() line: 593<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>CompilationUnitScope.faultInTypes() line: 447<span class="Apple-tab-span" style="white-space:pre">        <br></span>Compiler.process(CompilationUnitDeclaration, int) line: 752<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>Compiler.compile(ICompilationUnit[]) line: 464<span class="Apple-tab-span" style="white-space:pre">        <br></span>EclipseJavaCompiler.compile(String[], ResourceReader, ResourceStore, ClassLoader, JavaCompilerSettings) line: 358<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>EclipseJavaCompiler(AbstractJavaCompiler).compile(String[], ResourceReader, ResourceStore, ClassLoader) line: 49<span class="Apple-tab-span" style="white-space:pre">        <br></span>JavaDialect.compileAll() line: 369<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>DialectCompiletimeRegistry.compileAll() line: 53<span class="Apple-tab-span" style="white-space:pre">        <br></span>PackageRegistry.compileAll() line: 71<span class="Apple-tab-span" style="white-space:pre">        <br></span>PackageBuilder.compileAll() line: 869<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>PackageBuilder.addPackage(PackageDescr) line: 826<span class="Apple-tab-span" style="white-space:pre">        <br></span>PackageBuilder.addPackageFromDrl(Resource) line: 404<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>PackageBuilder.addKnowledgeResource(Resource, ResourceType, ResourceConfiguration) line: 586<span class="Apple-tab-span" style="white-space:pre">        <br></span>KnowledgeBuilderImpl.add(Resource, ResourceType) line: 37<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>DroolsTest.readKnowledgeBase() line: 52<span class="Apple-tab-span" style="white-space:pre">        <br></span>DroolsTest.main(String[]) line: 25<span class="Apple-tab-span" style="white-space:pre">        </span></blockquote></div>
<div><br></div><div>On the same lines, method isPackage on line 285, will try to load a &quot;class name&quot; and if it can&#39;t be found it will assume it was actually a package name and return true. </div><div><br></div>
<div>Again, an illustrative call stack:</div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br>CompositeClassLoader.getResourceAsStream(String) line: 128<span class="Apple-tab-span" style="white-space:pre">        <br></span>EclipseJavaCompiler$2.isPackage(String) line: 288<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>EclipseJavaCompiler$2.isPackage(char[][], char[]) line: 318<span class="Apple-tab-span" style="white-space:pre">        <br></span>LookupEnvironment.isPackage(char[][], char[]) line: 1262<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>PackageBinding.findPackage(char[]) line: 77<span class="Apple-tab-span" style="white-space:pre">        <br></span>PackageBinding.getTypeOrPackage(char[]) line: 196<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>MethodScope(Scope).getTypeOrPackage(char[], int, boolean) line: 2592<span class="Apple-tab-span" style="white-space:pre">        <br></span>MethodScope(Scope).getPackage(char[][]) line: 2266<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>QualifiedTypeReference.getTypeBinding(Scope) line: 69<span class="Apple-tab-span" style="white-space:pre">        <br></span>QualifiedTypeReference(TypeReference).internalResolveType(Scope) line: 130<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>QualifiedTypeReference(TypeReference).resolveType(BlockScope, boolean) line: 197<span class="Apple-tab-span" style="white-space:pre">        <br></span>SourceTypeBinding.resolveTypesFor(MethodBinding) line: 1370<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>SourceTypeBinding.methods() line: 1090<span class="Apple-tab-span" style="white-space:pre">        <br></span>SourceTypeBinding.faultInTypesForFieldsAndMethods() line: 593<span class="Apple-tab-span" style="white-space:pre">        <br>
</span>CompilationUnitScope.faultInTypes() line: 447<span class="Apple-tab-span" style="white-space:pre">        <br></span>Compiler.process(CompilationUnitDeclaration, int) line: 752<span class="Apple-tab-span" style="white-space:pre">        </span></blockquote>
<div><br></div><div>Turns out that getting a resource when it does not exist can be pretty expensive if you&#39;re compiling rules inside a big application with a lot of stuff on your classpath, and this approach ends up tying the compilation time of rules to the classloaders&#39; search space.  </div>
<div><br></div><div>I was wondering if we could have a better way to distinguish types and packages or at least a configurable way. The first things that come to my mind would be caching, in the lines of what is done for class loading in the org.drools.util.CompositeClassLoader. Or have two different strategies/implementations for the findType and isPackage methods, one that would assume that you respect java conventions and parse the string to say if it&#39;s a package or a type and another that wouldn&#39;t assume anything and use the getResourceAsStream as it&#39;s done today. Then, we could choose via configuration which strategy to use.</div>
<div><br></div><div>Any other ideas? Any work already being done in this area?</div><div><br></div><div>Cheers,</div><div>Leo.</div>







<div><br></div>