Skip to content

Conversation

@mkarg
Copy link
Member

@mkarg mkarg commented Sep 24, 2025

Closing #1824

Introduces a simple softreference-based cache for TransformerFactory to prevent expensive creation of new factories unless the configuration (= setting of security and factory class) has changed or memory was exhausted meanwhile.

@mkarg
Copy link
Member Author

mkarg commented Sep 24, 2025

While mvn validate passes successfully, I'd like to keep this PR in draft mode until I found the time to actually run a performance benchmark with SAXON, to see that the cache is actually effective and really solves the discovered problem. Will need some time, please stay tuned!

@mkarg
Copy link
Member Author

mkarg commented Oct 31, 2025

As announced recently, here is the benchmark result (please find the source code, build script, and test data attached
). Results are test iterations per second:

  • 4.0.6-RI without Saxon: 5 in 2.749302799 seconds
  • 4.0.6-RI using Saxon: 5 in 103.770735 seconds
  • PR-1855 without Saxon: 5 in 1.604390299 seconds
  • PR-1855 using Saxon: 5 in 2.379313601 seconds

This clearly proofs that JAXB-RI unmarshalls much faster using PR-1855 compared to 4.0.6-RI's original code. Both, Saxon and the JRE's original implementation, clearly benefit from this contribution, and Saxon is becoming useable now.

Hence, I am hereby removing the draft state, and kindly ask for a merge. 🙂

@mkarg mkarg marked this pull request as ready for review October 31, 2025 14:13
…untless expensive factory creations

Signed-off-by: Markus KARG <markus@headcrashing.eu>
@mkarg mkarg force-pushed the mkarg/massive-performance-problem-1824 branch from 2e705e6 to 8aa4b25 Compare November 3, 2025 07:02
@mkarg
Copy link
Member Author

mkarg commented Nov 3, 2025

@lukasj Kindly requesting your review. :-)

@laurentschoelens
Copy link
Contributor

Hard to make a more minimal MRE 😄
I'll look at this

@laurentschoelens
Copy link
Contributor

laurentschoelens commented Nov 3, 2025

gh-1824-diff.txt

@mkarg : this is what I would have done to fix your performance issue.

With actual 4.0.6 :

  • With Saxon : 5 in 64.100840667 seconds
  • Without : 5 in 0.632727292 seconds

With patched 4.0.7-SNAPSHOT :

  • With Saxon : 5 in 0.731846333 seconds
  • Without : 5 in 0.497841 seconds

@mkarg
Copy link
Member Author

mkarg commented Nov 3, 2025

Feel free to open an alternative PR if you think that yours is in any case better than mine. In the end, I am happy with any solution, as long as it finally solves #1824. 🙂

@laurentschoelens
Copy link
Contributor

laurentschoelens commented Nov 3, 2025

Well I don't want to take over your PR since you find the issue and provide a PR

My solution (IMHO) offers a retro-compatibility way since we don't know how users would modify cached-instance that would be grabbed outside JaxbContext.

And also provide cache handling on XmlFactory.createTransformerFactory in method createTransformer as well as createTransformerHandler in JAXBContextImpl

@mkarg
Copy link
Member Author

mkarg commented Nov 4, 2025

Again, I do not care which solution is picked, so I am okay with you opening another PR and closing mine in turn - as long as we see any solution in the next patch level release.

@laurentschoelens
Copy link
Contributor

@mkarg : created #1872

@mkarg
Copy link
Member Author

mkarg commented Nov 6, 2025

@eclipse-ee4j/ee4j-jaxb-impl-committers Kindly asking for review / merge. 🙂

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