I am using JAXB for xml parsing, are there any performance or memory utilization issues?
One thing to be mindful of is that JAXBContext.newInstance()
is a very slow operation. This is where a lot of reflection and class generation happens, leading to perm space issues mentioned by duffymo. Thankfully, JAXBContext
is thread-safe, so it's ok to cache one away and reuse it. Otherwise, I think it's safe to say that JAXB memory usage will be on-par (or maybe less) than a full DOM, and, of course, greater than SAX.
If you have very large documents, it's possible to process them in chunks with JAXB. The JAXB RI distribution includes an example of streaming with JAXB.
JAXB suffers from the same basic issues as DOM-based parsing, which is that generally speaking, the entire data data structure is held in memory at the same time. That said, it's generally less memory-hungry than a DOM API (with the possible exception of XOM).
Having said that, there are ways of using JAXB to read fragments of large documents in a stream-oriented fashion, if needs be. That's fairly exotic usage, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With