Mekanism Generators

Mekanism Generators

97M Downloads

ItemHandlerHelper.insertItem() related performance issue

mrjoes opened this issue ยท 4 comments

commented

Issue description:

I have a fairly beefy Minecraft server (5950x with plenty of RAM) running ATM6 pack. After upgrading to T4 ore processing setup the server started lagging. Profiling showed that it is related to an item insertion into Mekanism machines - it takes too long to validate if an item can be inserted. Everything is automated by xnet - it's very possible that one of the players is trying to insert an item that is rejected by a machine in a loop.

Steps to reproduce:

  1. Open https://spark.lucko.me/uWq5ArYpMq to check profile log
  2. 60% of tick time is spent in TileEntityItemStackToItemStackFactory.isValidInputItem(). I'm not very familiar with Mekanism internals, but I assumed from the call stack that it should cache valid recipes and it's not happening for some reason

I can share the world if it'll help.

Version (make sure you are on the latest version before reporting):

Forge: 1.16.5-36.1.2
Mekanism: 1.16.5-10.0.21.448
Other relevant version:

commented

We are having the same problems on our server which also has plenty of ram too and its so bad that nothing from mekanism is working anymore even the reactor or turbine but otherwise everything else works perfectly.

commented

OK, found what was causing it - xnet attempts to insert ore that Ultimate Smelting Factory does not want to accept, in a loop. Recipe check takes too long and causes the lag. Removing offending ore from the processing list fixed the performance issue and profiler graphs look way different: https://spark.lucko.me/CTlDhkhCFS

commented

Ya I do have some ideas which I will try to implement for 10.1 to improve our validity check performance further but the big thing I think mainly was probably related to how much it was trying to check if the ore could be inserted.

commented

Copying from what I just posted in our update preview channel on discord:

I've been doing a bunch of work on improving of our recipe lookups especially in relation to our slot validity checks for if an item is valid in the slot (aka any recipe exists for it). I also made a few other improvements, more info will be in the commit message that I plan to make later today after doing some more testing for recipe types I haven't fully tested yet after my rewrite. But back to the main case this is improving: Inserting or attempting to insert invalid items into machines being slow due to having to check a bunch of recipes to make sure it is actually not valid. For this picture (128 factories and hoppers each hopper has 5 different stacks that aren't valid for the factories) the brief profiling results I did are as follows:
Before (released version 10.0.21): ~24ms tick time with /forge tps and profiling https://spark.lucko.me/QKeHaI6Sre
After (local branch with changes): ~4ms tick time with /forge tps and profiling https://spark.lucko.me/WaF2xPvhMk

2021-04-10_11 48 30