Foam​Fix

Foam​Fix

97M Downloads

[idea] Reducing memory usage of ClassInheritanceMultiMap

bs2609 opened this issue · 8 comments

commented

In particular, empty maps, which make up the majority of instances, and consume memory despite storing no unique data.

commented

Unfortunately, none of the maps are actually empty, and I feel the logic to handle the case of "un-emptying" a map could outweigh the memory savings.

commented

(By the way, since you're here, would you mind if I integrated some of your dormant rendering bugfix PRs into FoamFix? This also implies backporting the fitting ones to earlier Minecraft versions, which Forge most likely won't do.)

commented

I was thinking of possibly having a singleton empty CIMM, with handling a bit like Chunk.NULL_BLOCK_STORAGE. That said, I'm not really sure about the practicality, I'll leave it as your decision.

In response to your question; no, I don't mind if you want to take on bugfixes for backporting.

commented

@bs2609 The singleton empty CIMM would have to turn itself into a non-empty CIMM, however, as entries are added to it as new entity types get spawned. I don't think the practicality is worth it, and I think there are other areas more worth focusing on (for instance, finding large areas of ArrayLists to trim - the latest commit should help that greatly).

commented

I don't think there's any need for an empty CIMM to keep track of types - as it always contains no entities, any query should return false regardless of the entity class. (something like this is what I'm thinking of, if this isn't a good explanation)

ArrayList trimming is certainly an easier win, if there's still more to be had.

commented

@bs2609 Does it always contain no entities, though? That's the thing I'm trying to get at - what do we do once an entity is added?

commented

How about having a wrapper CIMM, that delegates to an internal CIMM instance, which is initialised to the empty singleton and then lazily set to a real map?

Kinda like how Java optimises the backing storage for it's own collections, but one layer above.

commented

@bs2609 Maybe, I'd have to see the CPU performance differences for that though. No point saving a few megabytes if it slows everything down!

(By the way, my take on #4313 -> https://github.com/asiekierka/FoamFix/blob/4a610552bbc2b414a4f380beab555f8eb7fa748b/src/main/java/pl/asie/foamfix/coremod/staging/Patch4313.java )