gnembon / carpet-autoCraftingTable

autoCraftingTable extension for carpet-mod
GNU Lesser General Public License v3.0
80 stars 27 forks source link

Optimize recipe search by checking against last cached recipe before anything else #47

Closed FxMorin closed 2 years ago

FxMorin commented 2 years ago

Firstly, auto crafting tables can cause a performance impact when used very often in large farms. The main reason for this is due to the recipe lookup, which searches through all recipes.

So what I did was use the already existing last recipe, and attempt to check it first. This is a great performance boost since it drastically speeds up all the auto crafting tables in farms.

old = current state, new = with cache image Accidentally left the one with cache running for 10 seconds longer than the old one (after tick warp), either way, it shows the point.

image

As you can also see, the extra match against the last cache added 62ms to the total checks which are nearly negligible. So adding 62ms to all auto crafting tables is worth it for the performance boost that this offers.

FxMorin commented 2 years ago

As a side-effect, it fixes #46 Cause this is the same check which causes mass crafting to lag