Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use SAXParserFactory in AbstractUnmarshallerImpl for better performance #284

Closed
winne42 opened this issue Nov 28, 2023 · 0 comments · Fixed by #285
Closed

Re-use SAXParserFactory in AbstractUnmarshallerImpl for better performance #284

winne42 opened this issue Nov 28, 2023 · 0 comments · Fixed by #285

Comments

@winne42
Copy link

winne42 commented Nov 28, 2023

The current design of AbstractUnmarshallerImpl has a serious negative performance impact when unmarshalling many XML files, which could easily be avoided.

Most JAXB documentation found anywhere including the JAXB Users Guide recommend creating a single JAXBContext and then new Unmarshallers for every unmarshalling tasks (the Users Guide recommends using object pooling for best performance, but many JAXB users will never have read that remark; also, this approach is more complex).

My issue with using JAXB in this "standard way" is that AbstractUnmarshallerImpl.getXMLReader() creates a new SAXParserFactory for every new Unmarshaller:

  • This is potentially quite an expensive operation, because the JAXP Lookup Mechanism uses the notoriously slow ServiceLoader mechanism. (this can be avoided by using system environment variables or jaxp.properties, but I highly doubt that this is a well-known fact)
  • It also seems unintuitive that a new factory with the same parameters is built over-and-over-again (e.g., we don't build a new car factory for every car we build, do we?)

My suggestion would be to make the well-documented default use-case of unmarshalling faster by creating a singleton SAXParserFactory in AbstractUnmarshallerImpl and re-using it in getXMLReader().

antoniosanct added a commit to antoniosanct/jaxb-api that referenced this issue Dec 3, 2023
Signed-off-by: Antonio Santos Izaguirre <antoniosanct@gmail.com>
@lukasj lukasj linked a pull request Feb 15, 2024 that will close this issue
lukasj pushed a commit that referenced this issue Feb 15, 2024
Signed-off-by: Antonio Santos Izaguirre <antoniosanct@gmail.com>
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 a pull request may close this issue.

1 participant