While analyzing memory usage in All The Mods 10 for FerriteCore (total heap: 4.5 GB), I noticed that owolibs DerivedComponentMap feature increases memory usage by about 350 MB. I think the root cause is that the logic is applied to all stacks (about 2.75M instances in memory), rather than just those for items that implement a nontrivial deriveStackComponents (i.e. a very small fraction).
The additional memory usage has two separate causes:
- Calling
PatchedDataComponentMap::applyPatch/ComponentMapImpl::setChanges on a newly initialized component map will call ensureMapOwnership, even if the argument is an empty map as it is here. This causes the singleton returned by Reference2ObjectMaps.emptyMap to be replaced with a new Reference2ObjectArrayMap, which uses 72 extra bytes per stack. Since nearly all stacks in memory have empty patches, this means an extra memory usage of 72 * 2.75M = 198 MB. I implemented a more general fix for memory usage from these empty maps in the latest release for FerriteCore, but I think it would still be good if this was fixed on your end as well.
- Even when this is resolved, the feature results in noticeably increased memory usage. This usage is simply from the presence of two new object for each
ItemStack instance, one DerivedComponentMap (24 bytes shallow) and the PatchedDataComponentMap/ComponentMapImpl stored in it (32 bytes shallow). This works out to 56 * 2.75M = 154 MB of additional memory usage.
While analyzing memory usage in All The Mods 10 for FerriteCore (total heap: 4.5 GB), I noticed that owolibs
DerivedComponentMapfeature increases memory usage by about 350 MB. I think the root cause is that the logic is applied to all stacks (about 2.75M instances in memory), rather than just those for items that implement a nontrivialderiveStackComponents(i.e. a very small fraction).The additional memory usage has two separate causes:
PatchedDataComponentMap::applyPatch/ComponentMapImpl::setChangeson a newly initialized component map will callensureMapOwnership, even if the argument is an empty map as it is here. This causes the singleton returned byReference2ObjectMaps.emptyMapto be replaced with a newReference2ObjectArrayMap, which uses 72 extra bytes per stack. Since nearly all stacks in memory have empty patches, this means an extra memory usage of72 * 2.75M = 198 MB. I implemented a more general fix for memory usage from these empty maps in the latest release for FerriteCore, but I think it would still be good if this was fixed on your end as well.ItemStackinstance, oneDerivedComponentMap(24 bytes shallow) and thePatchedDataComponentMap/ComponentMapImplstored in it (32 bytes shallow). This works out to56 * 2.75M = 154 MBof additional memory usage.