In an earlier blog, I started a discussion about DOM vs. JAXB performance. For that purpose, I selected 4 different XML schemas, including 3 standard ones: UBL, FPML and GAML; in addition, I picked about 20 XML instances with sizes ranging from 1K to 924K and looked at number of Mbits per second I could process on a modern 2-way Opteron server. The results showed DOM coming just ahead of JAXB in a roundtrip test where the data was first unmarshalled/parsed from a memory buffer and the marshalled/serialized into a another memory buffer.
In my view, for this analysis to be complete it should also include performance of streaming APIs, memory consumption (as well as %GC time) and also a break up of the roundtrip cycle to understand where the time is going. In today's installment I'm addressing the latter for DOM and JAXB. Cutting to the chase, here are the results:
To ensure a steady state, this test was executed for more than 3 hours. And as you can see the results are very consistent regardless of the type of mean under consideration. Perhaps as expected, JAXB unmarshalling is slower than DOM parsing, but perhaps unexpectedly, JAXB marshalling is faster than DOM (Note the use of the the JAXB marshaller into OutputStream; results will most certainly vary if you opt to marshall into a StAX XMLStreamWriter, for example).
The JAXB RI team is currently investigating a more aggressive bytecode injection approach. This should help JAXB catch up, and perhaps even surpass, DOM in terms of roundtrip performance. I will most certainly update these results once the new implementation becomes available. In the meantime, I'll continue the analysis by adding streaming APIs to the mix and by analyzing memory consumption in upcoming installments. Stay tuned and happy benchmarking!