Cache compiled schematron Templates to avoid repeated XSLT compilation#1
Merged
jordanpadams merged 1 commit intomainfrom Apr 1, 2026
Merged
Conversation
Add a HashMap<String, Templates> cache to SchematronTransformer so that the expensive ISO schematron XSLT compilation is performed only once per unique schematron source string. Subsequent calls to transform(String) return a new Transformer from the cached Templates object. - Extract compilation logic into private compileSchematron() returning Templates - Add cache lookup in transform(String, ProblemHandler) - Add clearCache() method (naturally reset when LabelValidator.clear() creates a new instance) - Add debug logging for cache hits/misses Fixes: NASA-PDS#1565 Co-Authored-By: jordan.h.padams <jordan.h.padams@jpl.nasa.gov>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Adds an in-memory cache of compiled
javax.xml.transform.Templatesobjects toSchematronTransformer, keyed by the raw schematron source string. This avoids re-running the expensive ISO schematron → XSLT compilation for every label when the same schematron is used repeatedly (which is the common case).Mechanism: The existing compilation logic is extracted into a private
compileSchematron(Source, ProblemHandler)method that returnsTemplatesinstead ofTransformer. Thetransform(String, ProblemHandler)overload now checks aHashMap<String, Templates>before compiling; on a cache hit it callsTemplates.newTransformer()directly. Thetransform(Source, ProblemHandler)overload (used less frequently, and not keyed by a stable string) is not cached—it always compiles fresh.Cache lifetime is tied to the
SchematronTransformerinstance.LabelValidator.clear()already creates a new instance (line 219), so no changes are needed there. AclearCache()method is provided for explicit invalidation if needed.Ref: NASA-PDS#1565
Review & Testing Checklist for Human
HashMap: The cache uses a plainHashMap. IfSchematronTransformeris ever accessed from multiple threads concurrently (e.g., parallel label validation), this is a data race. Verify whether aConcurrentHashMapis needed by checking howLabelValidator/ validation rules use this class.ProblemHandlerignored on cache hit: On a cache hit, thehandlerparameter passed totransform(String, ProblemHandler)is silently unused — no error listener is set. Confirm this is acceptable (compilation already succeeded on first call, so there are no transform errors to report on the cached path).mvn test) and confirm identical validation results on a representative set of labels (e.g., a small bundle). The behavioral contract should be unchanged — same errors/warnings, same SVRL output — just faster on repeated schematron compilations.Notes
transform(String, ...)path is cached. Thetransform(Source, ...)path compiles every time sinceSourceobjects are not stably comparable/hashable.Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/e8943ca2e9de4879856766ebf367604c