hunterhacker/jdom

Technical question - measure memory footprint

Closed this issue · 1 comments

Hello,
I plan to use JDOM in my project because API looks very friendly. More friendly then Java W3C DOM. I was wondering did JDOM dev team measured memory footprint of created JDOM objects: Document, Element,...

The goal is to use xml structure as messaging object (xml is small, few KBytes) between Java microservices.
Probably there will be thousand of messages between microservices. When xml is received by microservice it will be converted to jdom2.Document. Will JDOM take to much memory ?

Best Regards,
Krešimir

rolfl commented

JDOM holds the entire XML document in-memory, and thus it's memory footprint grows linearly with-respect-to the source document, The typical XML document on-disk is UTF-8 encoded, and thus is typically 1-byte-per-character for most characters. In Java this becomes one char-per-character so the memory footprint is twice the size of the document's on-disk footprint. Then, there's also an overhead for each element, attribute, and so on. That typically is about 150 bytes per element/attribute/etc. That grows linearly with respect to the number of elements, etc.

For large XML documents (hundreds of megabytes) the memory footprint can become a significant issue.

For your purposes, I don't think a few KB is significant at all in-memory. I would not worry.

For each release of JDOM we measure the performance in both the time and memory domains: http://hunterhacker.github.io/jdom/jdom2/performance.html Those tables indicate that loading the "hamlet" document (273KB on disk) results in a 2MB memory footprint. The source document has about 10,000 elements, which translates to about 150bytes per element of overhead.

As for the actual memory footprint, it's a little hard to measure, but we did do some additional analysis when introducing the SlimJDOMFactory: http://markmail.org/thread/m2jmglhiqzaty42c There's more information here: https://github.com/hunterhacker/jdom/wiki/JDOM2-Feature-Reduced-Memory-Footprint.

Note that the performance tests measure the memory footprint using internal calls to the System memory statistics and is not 100% accurate.