Skip to content

perf: cache compiled XSLT Templates in MessageCodeGenerator#2

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/apply-code-generator-changes
Draft

perf: cache compiled XSLT Templates in MessageCodeGenerator#2
Copilot wants to merge 2 commits into
masterfrom
copilot/apply-code-generator-changes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

Ports performance optimization from quickfixj#1231 now that the code generator has moved to this repository.

createTransformer() was recompiling XSL stylesheets from scratch on every invocation. For FIX Latest with hundreds of files, the same handful of stylesheets were compiled hundreds of times.

Changes

  • Shared TransformerFactory: Moved from local variable to instance field
  • Templates cache: ConcurrentHashMap<String, Templates> keyed by absolute path (filesystem XSL) or "classpath:" + xsltFile (embedded resources)
  • Lazy compilation: First call per stylesheet compiles via newTemplates(), subsequent calls reuse cached Templates and call cheap newTransformer()
  • StreamSource handling: Created inside computeIfAbsent lambda to avoid stream consumption issues in edge cases
// Before: full recompilation per file
TransformerFactory tf = new net.sf.saxon.TransformerFactoryImpl();
return tf.newTransformer(styleSource);  // expensive

// After: compile once, reuse
Templates templates = templatesCache.computeIfAbsent(cacheKey,
    k -> transformerFactory.newTemplates(styleSource));
return templates.newTransformer();  // cheap

Copilot AI changed the title perf: cache compiled XSLT Templates per XSL file in MessageCodeGenerator perf: cache compiled XSLT Templates in MessageCodeGenerator Jun 3, 2026
Copilot AI requested a review from chrjohn June 3, 2026 18:27
@chrjohn chrjohn added this to the 3.0.3 milestone Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants