Create

Create

86M Downloads

Mechanical Mixer causes severe performance issues

twothe opened this issue ยท 13 comments

commented

Describe the Bug

See performance analysis here: https://spark.lucko.me/h83Fryu2Xh

In combination with Silent Gear (and potentially other mods) the Mechanical Mixer drains a crazy amount of CPU power on servers, as it is constantly running through all existing recipes to figure out what it is supposed to do. This happens even if the mixer has no input at all.

Please note that this is a single Mechanical Mixer that is not even producing anything, that is draining about 99% of server CPU time by checking what it can do with zero ingredients.

Reproduction Steps

  1. Run game with Silent Gear and Create
  2. Place a Mechanical Mixer
  3. Have it run on a high rotation speed

Expected Result

Create should use a recipe cache for mixers, as it is very likely that they are going to do the very same recipe over and over again. Additionally an empty basin should not cause any recipe lookup at all.

Screenshots and Videos

No response

Crash Report or Log

No response

Operating System

Windows 11

Mod Version

0.5.0

Minecraft Version

1.18.2

Forge Version

40.2.54

Other Mods

Silent Gear
Spark

Additional Context

No response

commented

I can also confirm that I'm having this same issue

commented

I'm also getting this issue. I run a server and running a TPS check while the Mechanical Mixer was active came back with almost 40k us/t.

commented

There is definitely another issue on the side of SilentGear here as well, but generally speaking it is a bug that the Mixer is constantly checking for the same recipe, even though just caching the last one would be sufficient in 99% of the cases, especially if it is empty.

This leads to performance issues with all bigger packs like ATM, even if SilentGear was not in it.

commented

I am also having the same issue.

Although, looking at the code, I am wondering if this is more on Silent Gear's side? It seems like the slowness comes largely from i.getItems() (line 81 in BasinRecipe.java) taking a long time
specifically for their recipes. Looking at their code, it seems that getItems() loops through every single item in the entire game and then filters for the ones that match that particular recipe, and that is happening for every single one of their recipes on every single mixer tick. I feel like that list of items should be precomputed at startup rather than generated in the moment, but I'm not super familiar with Forge modding so I'm not sure if there's a good reason for this that I'm not aware of. Regardless, a cache of the list of items for each recipe within Create might be worth having anyway since it would make the mod more resilient against other misbehaving mods.

commented

Here. having the same issue, can't confirm if it is because of silent gear or not, but i found out it was the mixer the one causing the problem with this https://spark.lucko.me/ZSBwoNUoV1.
Also a temporary fix for this would be to deactivate the mixer when it is not in use, i did this with a content observer facing the basin, with a redstone link, then invert the signal, so everytime there is an item in the basin, the mixer starts working again.

commented

Quick workaround for this is setting a filter on the basin, that prevents the look ups.

commented

On ATM7 I noticed that the mixers are extremely laggy if the basin outputs to a belt, but not at all when pulling output from the basin using e.g. pipez (even with a high speed upgrade). E.g. a very basic setup as shown in the picture below clearly shows the difference. The mixers are only powered and receive no input

https://imgur.com/a/KrGCGhA

commented

I just bumped into this bug, when using a filter on the basin the lag gets reduced. I think it has something to do with checking if the items in the basin and is they are contained in a recipe

commented

The reason this happens is because the recipe the basin is looking for is near the end of the list. So with a big modpack like ATM the basin has to potentially go through thousands of recipes every server tick to find that one it wants to produce. Which is a general issue with the way recipes are handled, but can be easily solved with a cache. Which makes a lot of sense with Create, as it is very likely that a single basin will create only one thing in it's entire lifetime.

The mod Fast Suite helps a bit on this by making a global JSON recipe cache, but it does not solve the underlying issue.

commented

The fix should probably be shortcutting when there is no input. And if that does not work, an increasing delay between recipe lookups if the previous attempt did not result in anything. And ideally smarter recipe lookups, but that I lack context on and is probably beyond control of the mod anyway.

With the staggered delays, it should be much more resource friendly, while still allowing it to operate at a very high throughput once it actually produces items since the delay then gets reset to its default low value.

commented

The reason this happens is because the recipe the basin is looking for is near the end of the list. So with a big modpack like ATM the basin has to potentially go through thousands of recipes every server tick to find that one it wants to produce. Which is a general issue with the way recipes are handled, but can be easily solved with a cache. Which makes a lot of sense with Create, as it is very likely that a single basin will create only one thing in it's entire lifetime.

The mod Fast Suite helps a bit on this by making a global JSON recipe cache, but it does not solve the underlying issue.

Are recipes searched one-by-one, or is there at least some algorithm to find recipes more quickly, like a tree model?

commented

The reason this happens is because the recipe the basin is looking for is near the end of the list. So with a big modpack like ATM the basin has to potentially go through thousands of recipes every server tick to find that one it wants to produce. Which is a general issue with the way recipes are handled, but can be easily solved with a cache. Which makes a lot of sense with Create, as it is very likely that a single basin will create only one thing in it's entire lifetime.

The mod Fast Suite helps a bit on this by making a global JSON recipe cache, but it does not solve the underlying issue.

It's not so much it being at the end of the list; the real problem is that Silent Gear regenerates its list every time you ask for its list of recipes, and it's the generation of the list that takes a long time. Searching through the list, while potentially inefficient, is a very insignificant portion of the time taken to actually do the recipe lookup. You can see this from the image I posted above

commented

But then still in a common Create setup the Basin will create the exact same recipe over and over again, so a constant look-up ain't even necessary.