The bug
Entity collisions severely impact performance even with collisionRule
set to never.
How to reproduce
Open a void world
/gamerule maxEntityCramming 10000
/team add noCollision
/team modify noCollision collisionRule never
/summon cow ~ ~ ~ {NoAI:1,Team:"noCollision"}
Run a few times:
/execute as @e[team=noCollision] at @s run summon cow ~ ~ ~ {NoAI:1,Team:"noCollision"}
Open the
SHIFT
+F3
debug graph for root.tick.level.entities.regular.tick.minecraft:cow and notice that "push" takes most of the time despite the collision rule
One can repeat the steps with NoAI
bats and see that they don't cause lag as bats (effectively) have the proposed fix already implemented.
Note that this bug affects all living entities within the same subchunk (a 16x16x16 unit of the world) and not only the same block.
Code analysis (official mappings)
The method LivingEntity.pushEntities
calls the costly Level.getEntities
even when it's known it will return an empty list.
A proposed fix is to shortcut the method when the collision rule is set to never.
Note that armor stands implement their own collision code but also suffer from this bug.
Attachments
Comments 7
Still present on 1.15.2. Note that the effects of this bug start to get noticeable after around 500 entities get spawned (9 runs of the execute command).
Canconfirm in 1.16.5
copying the entity list seems like only, 3% with 4k entities. also this is a client side only problem. collision is correctly ignored server side (or atleast turning the collision off improved tps by a few hundred percent)
Is the issue on 1.15.2 i can't reproduce it.