Template Data taking too much space in heap of client
KaktuszSok opened this issue · 7 comments
Context Environment
Minecraft version: 1.12.2
Ancient Warfare 2 version: ancientwarfare-1.12.2-2.7.0.1032
Minecraft Forge version: v2854
Was trying to find a memory leak and noticed that AW structures take up a huge amount of memory. Not sure if AW is the cause of the leak but players also reported major performance issues (120fps drop to 40fps) near AW structures long after they've been generated (i.e. it's likely not due to fallen items). Either way structure data should not hog client's memory.
Expected Behavior
When playing on a server, template data for structures should not be of significant footprint to the clients.
Current Behavior
~1GB of short[]s is used up by structure template data at all times.
Steps to Reproduce
- Launch minecraft
- Log on to server (possibly works from main menu too)
- Use VisualVM or similar to take a heapdump of MC
- The section "Classes by Size of Instances" is dominated by short[], with 1GB of information. All the biggest instances of short[] (ranging from 50MB to 1MB and possibly more) are referenced by templateData in net.shadowmage.ancientwarfare.structures.template.StructureTemplate.
Possible Solution
Only load template data as-needed from disk when the server is generating new chunks. Could slow down worldgen further so alternatively only load template data on server startup but not on game load. Ideally configurable.
This is already configureable. Instruct your server players to go to the configs folder, AW config folder, AW structure config file, and scroll down to “disable default pack” and have that setting be set to “false”. Note: singleplayer player worlds NEED to have this set to “true” for structures to spawn in singleplayer worlds.
This is already configureable. Instruct your server players to go to the configs folder, AW config folder, AW structure config file, and scroll down to “disable default pack” and have that setting be set to “false”. Note: singleplayer player worlds NEED to have this set to “true” for structures to spawn in singleplayer worlds.
It's seems that the town generate tool won't display entries without loaded templates in client
This is already configureable. Instruct your server players to go to the configs folder, AW config folder, AW structure config file, and scroll down to “disable default pack” and have that setting be set to “false”. Note: singleplayer player worlds NEED to have this set to “true” for structures to spawn in singleplayer worlds.
Good to know that's possible. Still it is not ideal for optimising packs where players may play both singleplayer and on server. In my case everyone plays on server but a) that's generally not the case for other modpacks and b) it introduces a config disparity between the server and clients which is best avoided for an easier update workflow.
No way to make this more optimized. Structure loading (to memory) happens during game loading, not when you load a world. There is no way to tell if a player will only use a dedicated server or they will load local worlds before they load up the world.
Also note, moving structure init to world load is absolutely not desireable as that would run every time you connect or load up a world and it would hugely impact world load times.
I see. What about a config option to only load a structure from disk when it is being generated? I would prefer to have slower worldgen, as that is occassional, rather than always having 1GB of data loaded into memory. Would also be fully sustainable as structures keep getting added and later down the line it would be unreasonable to always have 2+GB of data loaded for such sparing use.