Botany Pots

Botany Pots

33M Downloads

BotanyHelper.findCrop() Causing Lag

7OOTnegaTerces opened this issue ยท 2 comments

commented

I'm getting a lot of lag, and when I ran spark, one of the big offenders is this mod, specifically "BotanyHelper.findCrop()" and it's subcalls to BasicCrop.matchesLookup(), BotanyPotHelper.canCropGrow(), BasicSoil.canGrowCrop(), and String.equalsIgnoreCase(). Honestly, I have no idea why in the world your code calling this subroutine to check if what the pot is trying to grow is allowable so much. You should only ever check this exactly one time when the user tries to put in the seed. If it's okay, then you allow the seed and start the "grow the crop" function. No need to check if everything is good to go every time you start the "grow the crop" function, because the "grow the crop" function will never be called on an illegal setup. This is a super serious memory and time waster (especially the String.equalsIgnoreCase() one, that's a real memory and computational time hog, so it should be called as sparingly as possible), and it's making my save unplayable since I was trying to grow a whole bunch of Mystical Agriculture crops in a large botany pot field.

I really like this mod, and want to use it, but I need to be able to play the game more...

commented

I've put out an update for 1.20.1 that addresses most of your concerns by reorganizing the logic to call these methods less frequently. Locally this has resulted in a 40% reduction in pot tick time but your results will likely vary. The main motivation for validating this each tick is to account for changes to the game state that can not be easily listened to. For example there are crops that can only grow during certain times of day.

There's still room to further optimize this code but I am currently satisfied with how it performs. Further optimizations would likely require larger refactors that I am not planning right now. With the newest update I am also able to run 10k hopper pots without dipping below 20tps and the tick time of the hopper pot is nearly a third of the time a vanilla hopper takes.

commented

@Darkhax: Thank you for your hard work on this issue, you're awesome, and I'm an idiot! I forgot to mention that I'm running on Minecraft 1.18.2, and will be for a while, so I really needed an update to that version of the mod... If you can port your changes down, that would be great, but I understand if you cannot... :'(

P.S. - Also, thank you for getting the job done so quickly, you're obviously much more on top of things than I am! ;P