Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-151802

Spawning causes massive TPS CPU load on a flat world.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 1.14.1, Minecraft 1.14.2 Pre-Release 2, Minecraft 1.14.2 Pre-Release 3, Minecraft 1.14.2 Pre-Release 4, Minecraft 1.14.2
    • None
    • Confirmed
    • (Unassigned)

      Hi,

      There is a problem with spawning code, which can be clearly visible on the following clip:
      https://youtu.be/GGIoeO5btng

      tl;dr; in 1.14 A LOT has been added to entity contructor, which causes lots of CPU. Most mobs won't spawn anyways, so e.g. initializing their brains etc at Constructor rather than with some init() method afterwards is not a good idea. Second component to the CPU drain are collision checks (even before entity is created). 1.14 collision check code seems to be much more complex comparing to 1.13, and despite 1.13 calling it twice for each mob, one call in 1.14 costs about 10 times more. 

      Reproduction steps: create a flat world with one block (white concrete, why not), press Alt F3, observe TPS graph, ->doMobSpawning false, observe graph.

      Evidences:
      Full code (replaced factory method with simple cow constructor for clarity - no effect on the final result)

      [See Exhibit 1]

      Commented out collision check with predefined BBs (without creating a mob)

      [See Exhibit 2]

      Commented out entity creation code - taking a sample cow instead (so skipping CTOR)

      [See Exhibit 3]

        1. Exhibit 1.png
          Exhibit 1.png
          253 kB
        2. Exhibit 2.png
          Exhibit 2.png
          243 kB
        3. Exhibit 3.png
          Exhibit 3.png
          307 kB

            boq [Mojang] Bartosz Bok
            gnembon [Mojang] Gnembon
            Votes:
            31 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: