Description
A Spark (Flare) profiler session on our server revealed that EntityAIStompTurtleEgg is consistently triggering chunk loading during the entity AI update phase. This causes an expensive cascade every tick across all active Drowned entities:
com.sirsquidly.oe.entity.ai.EntityAIStompTurtleEgg.func_75250_a() 0.13%
net.minecraft.entity.ai.EntityAIMoveToBlock.func_179489_g() 0.13%
com.sirsquidly.oe.entity.ai.EntityAIStompTurtleEgg.func_179488_a() 0.13%
net.minecraft.world.World.func_180495_p() 0.13%
net.minecraft.world.World.func_175726_f() 0.12%
net.minecraft.world.gen.ChunkProviderServer.func_186025_d() 0.12%
net.minecraft.world.gen.ChunkGeneratorOverworld.func_185932_a() 0.07%
The block lookup in func_179488_a() (the shouldMoveTo check) calls World.getBlockState() → World.getChunk() → ChunkProviderServer.loadChunk() without first verifying whether the target chunk is already loaded. On servers with a healthy Drowned population this compounds significantly, as every Drowned runs this check every tick.
Impact
- Consistent 0.13% server thread usage per stack frame solely from this AI check
- Causes chunk generation to be triggered from entity AI ticks, which is unintended and can cause cascading slowdowns under load
- Scales linearly with Drowned count
Suggested Fix
Guard the block lookup in shouldMoveTo with a loaded-chunk check before doing any block access:
@Override
protected boolean shouldMoveTo(World world, BlockPos pos) {
// Only check blocks in already-loaded chunks
if (!world.isBlockLoaded(pos)) {
return false;
}
// existing logic here
}
This is a cheap check (just a chunk map lookup) and will prevent the AI from ever triggering chunk loading. Drowned will simply not path toward turtle eggs in unloaded chunks, which is the correct behaviour anyway, vanilla 1.13+ uses the same guard in its own EntityAIStompTurtleEgg implementation.
Alternatively, if you want slightly more range safety, you can check a radius around the entity rather than a single pos:
if (!world.isAreaLoaded(pos, 0)) {
return false;
}
Environment
- Cleanroom
- Oceanic Expanse 1.2.2
- Profiler: Flare
Description
A Spark (Flare) profiler session on our server revealed that
EntityAIStompTurtleEggis consistently triggering chunk loading during the entity AI update phase. This causes an expensive cascade every tick across all active Drowned entities:The block lookup in
func_179488_a()(theshouldMoveTocheck) callsWorld.getBlockState()→World.getChunk()→ChunkProviderServer.loadChunk()without first verifying whether the target chunk is already loaded. On servers with a healthy Drowned population this compounds significantly, as every Drowned runs this check every tick.Impact
Suggested Fix
Guard the block lookup in
shouldMoveTowith a loaded-chunk check before doing any block access:This is a cheap check (just a chunk map lookup) and will prevent the AI from ever triggering chunk loading. Drowned will simply not path toward turtle eggs in unloaded chunks, which is the correct behaviour anyway, vanilla 1.13+ uses the same guard in its own
EntityAIStompTurtleEggimplementation.Alternatively, if you want slightly more range safety, you can check a radius around the entity rather than a single pos:
Environment