The Aether

The Aether

32M Downloads

Optimization: optimizing handling of block related recipes to reduce overhead on block updates

shBLOCK opened this issue ยท 2 comments

commented

Currently, RecipeHooks.checkExistenceBanned() and RecipeHooks.sendIcestoneFreezableUpdateEvent are called for every NeighborNotifyEvent.
This causes lots of overhead on block updates. (the biome checking of checkExistenceBanned is especially bad, costing more than one ms every tick when there are lots of block updates happening)

The call site:

@SubscribeEvent
public static void onNeighborNotified(BlockEvent.NeighborNotifyEvent event) {
LevelAccessor levelAccessor = event.getLevel();
BlockPos blockPos = event.getPos();
RecipeHooks.checkExistenceBanned(levelAccessor, blockPos);
RecipeHooks.sendIcestoneFreezableUpdateEvent(levelAccessor, blockPos);
}

I'm not sure if this is intentional or not (if there are block recipes for the dimensions other than the aether), but if not, I think it'd be pretty easy to just add an early-exit condition on the dimension before checking the actual recipes and it'd get rid of this overhead (unless someone decides to build their whole base in the aether).

commented

I am a bit confused as to what biome checking youre referring to

commented

I am a bit confused as to what biome checking you're referring to

This bit. (level.getBiome() is the most time-consuming part)

public boolean matches(Level level, BlockPos pos, BlockState state) {
if (this.biomeKey != null) {
return level.getBiome(pos).is(this.biomeKey) && super.matches(level, pos, state);
} else if (this.biomeTag != null) {
return level.getBiome(pos).is(this.biomeTag) && super.matches(level, pos, state);
} else {
return super.matches(level, pos, state);
}
}