mojira.dev
MC-117087

Class.getSimpleName performance issue with large number of block entities

The bug

When there are large numbers of ticking block entities a lot of time is spent calling the class.getSimpleName() for the profiler, even though the profiler is not active.

Steps to reproduce

  1. Create a new superflat world and /tp 0 ~ 0

  2. Create a lot of ticking block entities: /fill 0 ~ 0 100 ~2 100 minecraft:furnace

Sampling results looks like this:

[media]

Code analysis (using MCP names)

In World.java there is a profiler section around each Block Entity's update call.

this.theProfiler.startSection(tileentity.getClass().getSimpleName());
((ITickable)tileentity).update();
this.theProfiler.endSection();

Internally, profiler code is wrapped in if (this.profilingEnabled) statements, but this call to getSimpleName() is not, and it can have an impact.

Attachments

Comments 2

See also: SPIGOT-1900, https://redd.it/5mcupg, and comments on this PR (requires spigot CLA).

The simple name of the class is pretty useless for the profiler under unremapped namings; you get things like this:

[04] |   |   |   |   blockEntities - 1.76%/1.25%
[05] |   |   |   |   |   unspecified - 62.03%/0.78%
[05] |   |   |   |   |   ave - 24.01%/0.30%
[05] |   |   |   |   |   avp - 6.95%/0.09%
[05] |   |   |   |   |   avr - 1.65%/0.02%
[05] |   |   |   |   |   avn - 1.45%/0.02%
[05] |   |   |   |   |   awf - 0.94%/0.01%
[06] |   |   |   |   |   |   unspecified - 99.41%/0.01%
[06] |   |   |   |   |   |   move - 0.39%/0.00%
[06] |   |   |   |   |   |   rest - 0.20%/0.00%
[05] |   |   |   |   |   avk - 0.63%/0.01%
[05] |   |   |   |   |   avd - 0.62%/0.01%
[05] |   |   |   |   |   avh - 0.60%/0.01%
[05] |   |   |   |   |   avu - 0.46%/0.01%
[05] |   |   |   |   |   ava - 0.33%/0.00%
[05] |   |   |   |   |   avl - 0.33%/0.00%

So it's a high performance cost for basically no gain. Also, that unspecified block is basically entirely the call to getSimpleName - even the vanilla profiler shows the problem.

My recommendation is to switch out from using the class' name to using either the name of the block (which is doable with the existing getBlockType() method) or using the block entity's name (which would need to have caching added, as currently that isn't stored anywhere and to retrieve it a lookup on the class must be performed).

Fixed in 1.12.1-pre1.

mezz

(Unassigned)

Confirmed

block-entity

Minecraft 1.11.2, Minecraft 1.12, Minecraft 17w31a

Minecraft 1.12.1 Pre-Release 1

Retrieved