Repository navigation
Description
Is your feature request related to a problem? Please describe.
While profiling PMD I noticed that a lot of time is spent in this stack:
com.intellij.util.lang.JarLoader.getResource(String)
com.intellij.util.lang.ClassPath.findResource(String)
com.intellij.ide.plugins.cl.PluginClassLoader.doFindResource()
com.intellij.ide.plugins.cl.PluginClassLoader.findResource(String)
java.lang.ClassLoader.getResource(String)
java.lang.Class.getResource(String)
org.xmlresolver.XMLResolverConfiguration.loadConfiguration(List, List)
org.xmlresolver.XMLResolverConfiguration.<init>(List, List)
net.sf.saxon.lib.CatalogResourceResolver.<init>()
net.sf.saxon.Configuration.init()
net.sf.saxon.Configuration.<init>()
java.lang.invoke.Invokers$Holder.invokeExact_MT(Object, Object)
jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl(Object[])
jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(Object[])
java.lang.reflect.Constructor.newInstanceWithCaller(Object[], boolean, Class)
java.lang.reflect.ReflectAccess.newInstance(Constructor, Object[], Class)
jdk.internal.reflect.ReflectionFactory.newInstance(Constructor, Object[], Class)
java.lang.Class.newInstance()
net.sf.saxon.Configuration.newConfiguration()
net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.initialize()
net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.<init>(String, XPathVersion, Map, XPathHandler, DeprecatedAttrLogger)
net.sourceforge.pmd.lang.rule.xpath.XPathRule.initialize(LanguageProcessor)
net.sourceforge.pmd.lang.rule.RuleReference.initialize(LanguageProcessor)
net.sourceforge.pmd.lang.rule.internal.RuleSets.initializeRules(LanguageProcessorRegistry, PmdReporter)
net.sourceforge.pmd.lang.impl.BatchLanguageProcessor.launchAnalysis(LanguageProcessor$AnalysisTask)
net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(List, List)
net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(List)
net.sourceforge.pmd.PmdAnalysis.performAnalysisAndCollectReport()
It looks like net.sf.saxon.Configuration.newConfiguration() is extremely slow as it always completely initializes everything for every XPath based rule that is in a RuleSet.
It looks like most performance is lost by constantly loading a xmlresolver.properties file in the upstream xmlresolver library:
https://github.com/xmlresolver/xmlresolver/blob/a45539745a596b17db4ab227ed6e6c4b53e6022a/src/main/java/org/xmlresolver/XMLResolverConfiguration.java#L373

Describe the solution you'd like
Performance should be improved here.
The XML should only be loaded once, maybe this needs to be fixed upstream or it's just a usage problem here.
Describe alternatives you've considered
N/A
Additional context
This is executed during IDE code highlighting where fast feedback is critical!
Activity
AB-xdev commentedon Oct 21, 2025
It might also be an idea to maybe skip
pmd/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
Lines 132 to 145 in 450dfe6
when
xpathRuleQueryis already present and the underlyingXPathHandleris identical to the previously used one.jsotuyod commentedon Oct 21, 2025
I'd not go so far as to not-reinitialize the
SaxonXPathRuleQuery, as that is very implementation dependent (ie: it would assume thatXPathHandlerimplementations are stateless / immutable, which is true right now, but may change over time).However, I think that adopting a single, statically shared
Configurationinstance would probably be feasible… the Saxon doc doesn't explicitly call it out, but it seems this is only a settings holder + factory, which would make it thread-safe. It also mentions that node identity is tied to the configuration, but that should not be an issue as far as I can tell… something we could play with for sure.Having said that, it would be great if we could put numbers to "Lot's of time spent doing XML initialization".
If you can share benchmarking data / microbenchmark results it would be great. Otherwise, it's really hard to asses the actual value of investing into this line of work…
AB-xdev commentedon Oct 22, 2025
According to the IntelliJ profiler (CPU time only):
performAnalysisAndCollectReporttook 76ms of which 38ms (50%) were spent with XML initialization. The rest was cacheFile validation and other overhead.As mentioned above our use case is on-the-fly analysis during code highlighting so every wasted ms counts ;)
AB-xdev commentedon Oct 22, 2025
I currently fixed this in the following way (at least no problems so far... however I only implemented it a few hours ago):
SaxonXPathRuleQuery#initialize: Globally caches theConfigurationandnamespacesToDeclarewhen the sameXPathHandleris usedRuleSetsinitializeRuleschecks if an XPathRule was already initialized and skips the initialization when the currentxPathHandleris identical to the one used previouslyI will try to post the code somewhere once this was finally implemented and tested by us internally.
[-]Performance: Lot's of time spent doing XML initialization[/-][+][core] Performance: Lots of time spent doing XML initialization[/+]zbynek commentedon May 16, 2026
@AB-xdev
Did you manage to implement and test your solution? A pull request would be helpful
adangel commentedon May 19, 2026
@zbynek
See the classes here: https://github.com/xdev-software/intellij-plugin-pmd/tree/develop/src/main/java/net/sourceforge/pmd
I have it on my personal TODO list to check these out and if it makes sense to integrate it in pmd-core...