Hi team,
I just took a memory dump of my application and I noticed that there is a considerable waste of memory due to the LinkedHashMap that backs JsonObjects.
From the public documentation :
/**
* Constructs an empty insertion-ordered {@code LinkedHashMap} instance
* with the default initial capacity (16) and load factor (0.75).
*/
public LinkedHashMap() {
super();
accessOrder = false;
}
This usually leads to objects such as :
LinkedHashMap(size:
2, capacity:
4) {(key:"email", val:"
em...@example.com"), (key:"standard", val:"Y")}
j.u.LinkedHashMap<String, ?>(size: 3, capacity: 16) {(key:"xxx", val:j.u.LinkedHashMap(size : 2, modCount : 2, threshold : 3, ...)), (key:"id", val:"123"), (key:"conf_cd", val:"LOW")}
I understand that this is how Java collection works, but is there anything we can do?
I was thinking that perhaps we could add a new constructor of JsonObject that allows configuring the initialCapacity and loadFactor but I do not think that this will fix the problem permanently as there are many other places that we use JsonObject.
Adding a default capacity in the original constructor may lead to considerable CPU waste due to the resizing needed.