Majrusz / MajruszLibrary

Library with common code for my Minecraft modifications.
8 stars 6 forks source link

Memory Leak causing lag on SMP #15

Closed katubug closed 1 year ago

katubug commented 1 year ago

Minecraft 1.19.2 Forge 43.2.8 Majrusz Library 3.3.0 Majrusz Enchantments 1.8.1

Servers with my modpack, Cottage Witch, have been experiencing serious lag issues, and we've had trouble identifying the memory leak until now.

IDK if this link will persist, but here's a spark report of one of the servers: https://spark.lucko.me/oWf6vtxBCw

One of our users had this to say:

"GameModifier trying to apply enchantments effects. there's a nasty memory leak and lock usage that lag along the path of this implementation"

image

"the mod is using the stream API to loop on all slots/enchants (?) of each entity, probably every tick stream API can cause locking and cloning depending on how you use it.

enchantment API isn't build for systemic scan every tick on each entity.

fix usually imply to avoid stream or even any form of loop on every entity every tick: filter early (empty slot or no enchant => don't scan), and only scena scarcely (when the mod spawn or at most every few seconds). and never ever clone objects every ticks: use flywheels or some form of caching."

I googled "com.mlib.gamemodifier" and found your mod, but I'm unsure whether this issue is caused in the library mod alone or only with the Enchantments mod. I am also using Majrusz' Accessories.

My users all love both your mods and I deeply want to keep them in the pack, but this lag issue has been absolutely crippling and I will have to resolve it somehow. I understand this is probably a core part of how your mods work, and would require a lot of changes to fix, but is this possible? And if it is not possible, can I escape the issue by removing only the Enchantments mod but keep the Accessories mod?

Thanks for your time!

katubug commented 1 year ago

My report is a duplicate of this one: https://github.com/Majrusz/MajruszLibrary/issues/16