AgriCraft

AgriCraft

30M Downloads

Crop.isFertile() CPU Usage

RlonRyan opened this issue ยท 4 comments

commented

Based off of my recent metrics, it has come to my attention that the Crop.isFertile() method is called almost every tick, so long as the crop is not mature. This means that the performance of the method is of great import to the overall performance of the server. Based off of recent investigation, it appears that the isFertile() method has a long call chain involving the GrowthRequirementHandler.getGrowthRequirement() method all the way to the growth requirement class.

sampling-1

Note that the total time 102ms, accounting for ~26% of the total tick time in the basic dev setup.

My recommendation would be to only check if the crop is fertile when planted and mark the plant as fertile or not, and only change this when the chunk is registered as changed? That way the function would only be called when absolutely necessary, and cut back on the tick time.

I am not sure as to how such should be implemented, and am thereby creating this issue as to consult the powers at be.

commented

I'll have a look at that.

commented

I am not terribly sure how accurate the numbers are, but it is nonetheless a good place to look into.

commented

That is the client thread though, its checking isFertile every tick when looking at it, on the server it's called on growth ticks only.
Bu still, I wan't aware it was that slow, caching it as a field and somehow updating it when the chunk updates would be better.

commented

I think we are getting ahead of ourselves here and pre-optimizing. Plus, I think that might have been a bad sample.