mojira.dev
MC-158597

Substantial lag due to collisions even with collisionRule set to never

The bug

Entity collisions severely impact performance even with collisionRule set to never.

How to reproduce

  1. Open a void world

/gamerule maxEntityCramming 10000
/team add noCollision
/team modify noCollision collisionRule never
/summon cow ~ ~ ~ {NoAI:1,Team:"noCollision"}
  1. Run a few times:

    /execute as @e[team=noCollision] at @s run summon cow ~ ~ ~ {NoAI:1,Team:"noCollision"}
  2. 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

Is the issue on 1.15.2 i can't reproduce it.

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)

[media]

Can confirm in 1.17.1.

This issue does not seem to be client-side only, but it is much worse client-side.

Still a problem with client-side in 21w40a

Zonteek

(Unassigned)

Confirmed

Platform

Normal

Collision, Performance

1.14.4, 19w35a, 19w38b, 19w39a, 19w41a, ..., 21w40a, 1.18 Release Candidate 4, 1.18, 22w05a, 1.19 Pre-release 1

Retrieved