Repurposed Structures (Forge)

Repurposed Structures (Forge)

21M Downloads

Memory leak in biome cache

BlueAmulet opened this issue ยท 5 comments

commented

private static final Map<IWorldReader, Map<Long, Biome>> MINI_BIOMEPOS_CACHE = new HashMap<>();

This cache holds WorldGenRegion -> map(positions -> biomes), however it keeps the region objects alive in memory and over time this region -> map fills up with tons of entries and memory usage grows. I changed this to a WeakHashMap and the number of entries stayed pretty low and memory usage didn't go up after each new world.

commented

To be clear after some digging, the processor was storing the worldgenregion which while it is a world, it's not the single world itself. It's a temporary restricted world used for worldgen which meant as you explored and generated more grassy igloos, that cache kept growing. The WeakHashmap was indeed the solution so it throws out the WorldGenRegion when it is finished with worldgen
image

commented

Thank you! I'll put this in next update. How did you find the leak and narrow it down to that code?

commented

Now I'm super curious. How many worlds saves are you even creating in single player? I had to make 20 worlds back-to-back to even notice any memory increase lol
image

commented

I've actually been testing out a modpack and have been noticing over time memory fills up to the point it's doing full GC every second. In the resulting heap dumps the MINI_BIOMEPOS_CACHE object usually stood out with high amounts of memory consumption.

But yeah I also had to create several worlds back to back. I also put some debugging messages in the computeIfAbsent function that shows how many entries were in the cache every time it added a new one, since sometimes making a new world doesn't immediately trigger adding stuff to the cache.

commented

The processor only runs and adds the world to the cache if the grassy igloo generates. New version of RS is now released so updating should fix it