Electroblob's Wizardry

Electroblob's Wizardry

18M Downloads

Memory leak from PlayerAnimator with Rats "Chef's Toque" item

Ricket opened this issue ยท 1 comments

commented

Minecraft version: 1.12.2
Wizardry version: 4.3.4
Environment: Server

Issue details: Minecraft starts extreme memory leaking, hits the limit, experiences long GC pauses. I took a heap dump and the majority memory is taken by playerLayerModels inside of PlayerAnimator:

image

Looking at the contained items, there are a lot of ModelChefToque from the rats mod (I have version rats-3.2.14-1.12.2):

image

In the game, I had received a "Chef's Toque" item from a loot crate and I put it into the helmet/head slot.

Other mods involved: rats-3.2.14-1.12.2

commented

Possibly related to #669.

Rats is creating a new armour model every single tick: https://github.com/Alex-the-666/Rats/blob/4f4f24a94a885540ce87be9fbdf7ddd80bf9c10b/src/main/java/com/github/alexthe666/rats/server/items/ItemChefToque.java#L23
https://github.com/Alex-the-666/Rats/blob/4f4f24a94a885540ce87be9fbdf7ddd80bf9c10b/src/main/java/com/github/alexthe666/rats/client/ClientProxy.java#L330

Compare that with how I do it for wizard armour:

public static final Map<ArmorMaterial, ModelBiped> wizard_armour_models = new HashMap<>();
static {
wizard_armour_models.put(Materials.SILK, new ModelWizardArmour(0.75f));
wizard_armour_models.put(Materials.SAGE, new ModelSageArmour(0.75f));
wizard_armour_models.put(Materials.BATTLEMAGE, new ModelRobeArmour(0.75f, true));
wizard_armour_models.put(Materials.WARLOCK, new ModelRobeArmour(0.75f, false));
}
/** The wrap width for standard multi-line descriptions (see {@link ClientProxy#addMultiLineDescription(List, String, Style, Object...)}). */
private static final int TOOLTIP_WRAP_WIDTH = 140;
// Registry
// ===============================================================================================================
@Override
public ModelBiped getWizardArmourModel(ArmorMaterial material){
return wizard_armour_models.get(material);
}

Normally the performance impact is minor but because PlayerAnimator has to modify and then cache those models, it fills up the memory very quickly with old model objects. I should be able to add a safeguard against this by ignoring models if there are more than a certain number belonging to the same class. However, this is a bug in Rats because there is no need to create new model instances every tick.