
[FEEDBACK] Botany plants should be caching the recipe and not call it every tick
wolfieboy09 opened this issue ยท 2 comments
Minecraft Version
1.18.2
Mod Version
8.1.29
Mod Loader
Forge
What environment are you running the mod in?
Don't Know / Not Applicable
Issue Description
When running a spark profile thingy, this mod is calling the recipe stuff every tick
The pots should cache the result and not have to do this
Offending code:
BotanyPots/Common/src/main/java/net/darkhax/botanypots/BotanyPotHelper.java
Lines 134 to 150 in 4db1d53
Thing: https://spark.lucko.me/9DZIZySIOE (stoneblock-3 modified)
Something that could help speed things up is using a weak hash map to do an initial lookup using the Item ID + pot soil as the key.
If the combination of them exists, check if the crop matches the lookup. If either they don't exist on the map or if the crop does not match the lookup, then you do the more exhaustive lookup through the recipe manager.
Using a weak hash map would allow the garbage collector to clean up the hashmap as it sees fit without creating a memory leak.
Additionally, this section could be optimized by simply using TreeSets.
You could get both categories, loop over whichever is smaller, and if the larger set contains an element in the smaller one, return true.
The TreeSet would allow you to do a case-insensitive contains check.