Reputation: 12222
I'm doing a very basic test of performance to unmarshal huge zipped XML file to a basic data structure.
I use the same input stream and same unmarshaller created from JAXB Context.
Simple approach - default JAXB - takes 18 seconds
unmarshaller.unmarshal(createFileInputStream());
Wrap input stream in SAX source to (I think) force using SAX - takes 20 seconds
unmarshaller.unmarshal(new InputSource(createFileInputStream());
Trying to force using STAX - takes 40 seconds !
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(createFileInputStream());
unmarshaller.unmarshal(reader);
To compare simple STAX stream reader loop to extract same data needs only 14 seconds.
I was looking at Can JAXB parse large XML files in chunks
Why default approach (passing the input stream) is faster than both SAX and STAX? What is used by default?
Why STAX approach is sooo slooooow while it's a recomended approach in mentioned article?
Upvotes: 0
Views: 136
Reputation: 2250
Some thoughts:
unmarshaller.unmarshal(inputStream)
under the hood does exactly what you do in your 2nd approach: Wrap the input stream in a SAX InputSource. So your approach 1 and 2 should be equally fast.reader
(.getClass().getName()
) to make sure it is what you expect.
XMLInputFactory
instead of always creating a new instanceXMLStreamReader
after use (may have performance benefit according to e.g. Woodstox documentation)Upvotes: 0