mojira.dev
MCPE-109299

Experience orb accumulation causes excessive lag

xp_orb entities cause significant lag when they accumulate in mobs farms. This seems to be because they have mob collision boxes. The game has to repeatedly calculate their collisions with each other and with mobs. Most mobs drop 3 xp_orb each upon death, so the number of collisions being calculated increases exponentially as a mob farm runs. By contrast, item drops do not produce nearly as much lag because they do not have mob collision. I would expect xp_orb entities to interact with block collision boxes, pistons, and liquids like item entities do, and not to overload the game server and client with mob collision calculations.

The attached test world,

[media]

, can be used to compare lag produced by item entities and xp_orb entities. It consists of repeat command bocks that generate either one item entity or one xp_orb entity with each tick, and an impulse command block that kills all entities to reset the test.

Steps to reproduce

  1. Use a performance monitor to track CPU usage and FPS. The monitor included with the XBox Game Bar in Windows 10 works for this.

  2. In the attached test world, turn on the lever on the diamond block to drop item entities.

  3. Allow the game to run for 5 minutes or so and observe the performance monitor.

  4. Turn off the lever and press the kill button to reset the test environment.

  5. Turn on the lever on the gold block to drop xp_orb entities.

  6. Allow the game to run for a few minutes and observe the performance monitor.

  7. Turn off the lever and press the kill button to reset the test environment.

Expected result

The performance monitor shows similar changes in steps 3 and 6.

Actual result

In step 6, but not in step 3, CPU usage climbs steadily. If the xp_orbs are within the player's view, then from a certain point FPS declines steadily (FPS decline begins at about 45 seconds on my computer).

Related issues

Attachments

Comments

migrated
[media]
GoldenHelmet

Note that this is not new in 1.16.100. It is as old as the game, as far as I can tell.

This may be the cause behind MCPE-89260.

To give some meaning to the number of orbs generated in the test world, consider that the number of experience orbs at which I start to experience FPS dropping in the test world is
1/tick * 20 tick/s * 45 s = 900
Then consider the following:

  • Experience orbs exist for 5 minutes before despawning.

  • The spawn algorithm runs once every 9 seconds in each chunk, on average (11/2000 chance each tick).

  • A decent mob farm might cover 4 chunks and have 6 levels.

  • Although not every spawn attempt succeeds in spawning a mob on each level of a farm, some mobs spawn in herds of > 1 mob at a time, so we can estimate the average spawns per level, per attempt to be 1.

  • Each mob kill produces 3 experience orbs

Given these numbers, the number of experience orbs existing during continuous operation of a mob farm, if they are not being picked up by the player, would be:

5 * 60 * ( 1 / 9 ) * 4 * 6 * 1 * 3 = 2400

migrated

Can confirm.

GoldenHelmet

After further testing, it appears not to be mob collision that makes XP orbs laggy. Instead, it is just the sheer number of entities.

I determined that mob collision can be removed from xp_orb entities with a behavior pack with this setting:

"minecraft:pushable": {
        "is_pushable": false,
        "is_pushable_by_piston": true
      },

I also attempted to remove the xp_orb collision box by setting its collision box to 0.0, but orbs were still able to push mobs. I also tried

"minecraft:physics": {
    "has_collision": false
  }

but that didn't seem to do anything.

To compare with items fairly, I created a pack that would make ravager saddle drops not require player kill, and used command blocks to summon and kill them at the same rate I was summoning XP orbs. The effects were the same for each: FPS started dropping at about 45 seconds, and by 5 minutes my CPU usages was at 60% and FPS was 7.

tryashtar

In 20w45a (1.17 snapshot), Java Edition made experience orbs merge under certain conditions. Bedrock has yet to port this 1.17 feature.

migrated

This still affects 1.19.31 (and every earlier version)

 

sculk catalyst may offer a workaround

GoldenHelmet

The 1.19.60 changelog states that orbs can now merge:

  • Orbs spawned within the same block will merge and combine XP values until orb limit is reached

If they do then I would consider that a fix to this bug. However, I do not see any evidence from in-game testing that this change has actually been implemented. If parameters were copied from Java then this could be related to MC-217855.

GoldenHelmet

Fixed by the fix for MCPE-167247.

GoldenHelmet

(Unassigned)

448558

Community Consensus

Multiple

1.16.100, 1.16.200, 1.19.50

1.20.0

Retrieved