Possible HashSet memory improvement
Philippe Marschall
kustos at gmx.net
Sat Oct 5 18:39:44 UTC 2013
Hi
I attended Nathan Reynolds Java Memory Hogs [CON4695] talk where he
talked about about memory waste in Java collections and attempts in 7u40
and later to improve the situation.
One thing he mentioned was that there is a patch floating around that
makes HashSet no longer use HashMap. This would allow us to remove the
"value" instance variable in a table entry. My limited understanding of
object layout and padding leads me to believe that this would not
improve the memory consumption of HashSet right now because the table
entries would still get padded to the original size. We would somehow
need to save another word.
Then I remembered something else he said, some instance variables of
some objects are almost always null. Well the "next" instance variable
of the table entry should be null most of the time (unless we have a
collision).
If we make different classes for the last entry and the other entries in
a collision chain we can reduce for entry size from 6 to 4 words (if my
understanding and calculations are correct) in most cases. This could in
theory reduce HashSet memory consumption by up to 28% (with no
collisions at all and 100% load factor).
Is there something I missed? Is this something that has been considered?
Cheers
Philippe
More information about the core-libs-dev
mailing list