[jdom-interest] JDOM and memory
Rolf
jdom at tuis.net
Mon Jan 2 12:27:40 PST 2012
Hi all.
Memory optimization has never been a top priority for JDOM. At the same
time, for what it does, JDOM is not a 'terrible' memory user. Still, I
have done some analysis, and, I believe I can trim about a quarter to a
half of 'JDOM Overhead' memory usage by making two 'simple' changes....
The first is to merge the ContentList class in to the Element class (and
also in to Document). This will reduce the number of Java objects by
about half, and that will save about 32 bytes per Element at a minimum
in a 64-bit JRE. Additionally, by lazy-initialization of the Content
array, we can save memory on otherwise 'empty' Elements.
This can be done by extending the Element (and perhaps Document) class
to extend 'List'. It can all be done in a 'backward compatible' way, but
also leads to some interesting possibilities, like:
for (Content c : element) {
... do something
}
(for backward compatibility, Element.getContent() will return 'this').
The second change is to make the AttributeList instance in Element a
lazy-initialization. This would save memory on all Elements that have no
attributes, but would have an impact for people who sub-class the
Element class and may expect the attributes field to be non-null.
I am trying to get a feel for how important this sort of optimization
may be. If there is interest then I will make some changes, and test the
impact. I may make a separate branch in github to test it out....
If the above changes are unrealistic then I don't think it makes sense
to even try....
Rolf
More information about the jdom-interest
mailing list