Knokko's Custom Items

Knokko's Custom Items

37.4k Downloads

Container performance

knokko opened this issue ยท 6 comments

commented

Someone encountered a lot of lagg due to custom containers. I think it is time to improve their performance. Ideas:

  • Decrease the update frequency to ~1 per second when the container has been idle for ~5 seconds (with idle, I mean that the container has items in its inventory, but is not performing any recipe).
  • When in the middle of a recipe, only check whether the current recipe is still available (all ingredients are still present) rather than iterating over all recipes.
commented

Using 20 active custom containers with 1 custom recipe and 100 active custom containers with 24 custom recipes, the spark plug-in reported that my container handlers consumed 4.5% of the server tick time. In this scenario, all containers contained exactly 1 item in the inputs.

commented

By putting more items in the containers, I was able to raise the tick consumption to 5.0%.

Inspecting the report suggested that most of that time was spent in ItemUtils.isEmpty (due to the GeneralItemNBT.readOnlyInstance, which requires to access nbt, and thus nms, which requires copying the entire item stack due to the stupid bukkit system). I could try to improve this by using some kind of system to check if an item is empty without needing to clone it somehow...

commented

My attempt to speed up ItemUtils.isEmpty failed, so I will have to focus on the update frequency.

commented

My first performance improvement reduced the plugin usage of the testcase described above from 5% to 0.1%.

I also made a new test case that doesn't benefit from that performance improvement (I will do another performance improvement to also help with this testcase). In this testcase (128 custom containers that are continuously working on a long-duration recipe and have both a crafting and fuel indcator), updating the containers took up 2.5% of the tick time.

commented

My second performance improvement reduced the tick time consumption of my second test case from 2.5% to 0.5%. Also a big improvement, but not as huge as the first one. The current performance bottleneck is the time needed to check whether a container recipe can be continued (to ensure players can't just take the items away).

commented

My third performance improvement addresses this bottleneck and reduced the consumed tick time of the previous testcase from 0.5% to 0.06%. I consider this sufficient.

These performance improvements will be included in Custom Items 9.