When I installed H&C on my server, it began to lag heavily. After profiling the server with WarmRoast, I realized that the lags were caused by climate calculations in the defeatedcrow.hac.core.event.BlockUpdateDC#onUpdate(defeatedcrow.hac.api.recipe.DCBlockUpdateEvent) method.
The Fixes Description
This PR fixes these issues:
It looks like that the clm variable (IClimate clm = ClimateAPI.calculator.getClimate(world, p);) is calculated on each block update, but sometimes not used further. I made it lazy, so the climate calculates only on first access.
Also, the clm2 variable (IClimate clm2 = ClimateAPI.calculator.getClimate(world, p.down());) is calculated for every IGrowable block regardless of whether it really needed. I moved the climate calculation into the right scope, so it will work fine now.
Lastly, the recipe lookup (IClimateSmelting recipe = RecipeAPI.registerSmelting.getRecipe(clm, new ItemStack(block, 1, meta));) uses an instance of IClimate. I refactored some code to make it check the input ItemStack firstly, and, only if it matches, calculate the climate and check it.
Motivation
When I installed H&C on my server, it began to lag heavily. After profiling the server with WarmRoast, I realized that the lags were caused by climate calculations in the
defeatedcrow.hac.core.event.BlockUpdateDC#onUpdate(defeatedcrow.hac.api.recipe.DCBlockUpdateEvent)
method.The Fixes Description
This PR fixes these issues:
clm
variable (IClimate clm = ClimateAPI.calculator.getClimate(world, p);
) is calculated on each block update, but sometimes not used further. I made it lazy, so the climate calculates only on first access.clm2
variable (IClimate clm2 = ClimateAPI.calculator.getClimate(world, p.down());
) is calculated for every IGrowable block regardless of whether it really needed. I moved the climate calculation into the right scope, so it will work fine now.IClimateSmelting recipe = RecipeAPI.registerSmelting.getRecipe(clm, new ItemStack(block, 1, meta));
) uses an instance ofIClimate
. I refactored some code to make it check the inputItemStack
firstly, and, only if it matches, calculate the climate and check it.Profiling Results
Before
After
Notes
That pull request needs to be merged too: https://github.com/defeatedcrow/HeatAndClimateMod/pull/37.