Repository navigation
[core] Fix #7072: Reuse compiled violationSuppressXPath queries - #7073
Merged
Merged
Conversation
aoto-tech
marked this pull request as ready for review
September 14, 2026 14:23
# Conflicts: # docs/pages/release_notes.md
Contributor
|
Compared to main: (comment created at 2026-10-08 19:14:36+00:00 for b2235dd) |
adangel
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the PR
violationSuppressXPathcurrently creates a newSaxonXPathRuleQueryfor every candidate violation. I moved that code into a dedicated suppressor and cache the compiled query in the AST user map, keyed by rule identity.The cache stays lazy and scoped to one rule and one file. That matters here because the compiled query includes the rule properties and the language-specific XPath handler. With N candidate violations, the XPath is now compiled once and still evaluated N times.
I added tests for reuse within one rule/file, separation across rules and files, and the resulting suppressed and unsuppressed violations. I ran
./mvnw.cmd -pl pmd-core verify: 6,460 tests, 0 failures, 0 errors, 11 skipped, and 0 Checkstyle violations.I also benchmarked this on an OCI Arm instance (4 vCPU, JDK 21). A synthetic case with 10,000 candidate violations went from a 6.155 s median to 3.435 s over 10 runs (44.2% less time), with byte-for-byte identical CSV output. A control without
violationSuppressXPathwas unchanged (3.425 s vs 3.455 s).Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)