eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
206 stars 114 forks source link

Massive Performance Problem: JAXB Creates hundreds of TransformerFactories #1824

Open mkarg opened 5 days ago

mkarg commented 5 days ago

As documented in https://saxonica.plan.io/boards/3/topics/9475?r=9566 we came across a massive performance problem when using Saxon XSLT engine. Saxon is optimized for reuse, so creation of a TransformerFactory is very slow (10 times slower as default engine bundled with OpenJDK), but the actual marshalling and unmarshalling is super fast. Unfortunately, for non-trivial contexts, JAXB-RI creates huge amounts of TransformerFactories (not just Transformers). So in the end, JAXB-RI on Saxon is hundreds of times slower than on JDK.

IMHO it is a good idea that Saxon precreates things when creating a Factory (so creating Transformers is fast) and what JAXB-RI does is, let's say, "uncommon": Creating lots of Factories (instead of just Transformers).

I did a quick test-drive which proofs that JAXB-RI on Saxon is not slow once I patched JAXB-RI to re-use the same TransformerFactory instead of creating new factories. I could provide a PR, but I wonder if there is something I am missing here? Is there a good reason to create a new factory always? Will reusing Factories (not Transformers!) break something?

mkarg commented 3 days ago

@lukasj Does it makes sense to set up a PR for factory caching or do you see architectural constrains that this would violate?