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.
1
Simple approach - default JAXB - takes 18 seconds
unmarshaller.unmarshal(createFileInputStream());
2
Wrap input stream in SAX source to (I think) force using SAX - takes 20 seconds
unmarshaller.unmarshal(new InputSource(createFileInputStream());
3
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
Question
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?