mojira.dev
MC-101792

Predicate overrides cause major FPS loss

Applying a large number of predicate overrides to an item in a resource pack will cause considerable FPS loss if the item is rendered too many times (example: armor stand head/hand slot).

Steps to recreate:

1- Download provided resource pack
2- Apply resource pack
3- Use the following command: "/give @p armor_stand 1 0 {EntityTag:{ArmorItems:[{},{},{},{id:diamond_hoe,Count:1,Damage:0s}]}}"
4- With the given item, place down 100* armor stands
5- Use the following command: "/replaceitem entity @e[type=ArmorStand] slot.armor.head diamond_axe 1 0"
6- Compare difference of FPS between diamond hoe (with 1,561 overrides applied) and diamond axe

*this number may vary depending on machine.


Code analysis by @unknown in this comment

Related issues

Attachments

Comments

migrated
[media]
migrated

A resource pack containing a diamond hoe assigned 1,561 damage value overrides.

onnowhere

Seems like minecraft is loading every single model in the file rather than just the specific model itself?

migrated

Confirmed. I'm dropping from ~950 FPS without AS to ~100 FPS with resourcepack applied and 100 of such AS with a dia hoe,
(adding to it is likely "Exponential lag because of entities in 1.9", MC-98822) and going up to ~350 FPS when I replace the dia hoe with a dia axe.

samasaurus6

Can Confirm. Also experienced this lag before. Reckoned it was due to model complexity, but even just using BUILT-IN models for the predicate overrides, there is major lag. Getting an FPS drop from 900FPS to 170FPS just from holding an inventory full of hoes...

Seems like all models for the predicates are "loaded" despite only one being seen at a time.

This is the best case scenario too. Map-makers rely on predicates to add models to maps without being limited to just the in-game items. Combine the predicate lag with complex models and you get some very resource heavy maps...

NeunEinser

The difference between them is for me ~210 FPS with the dimand axe, ~80 FPS with the hoe and ~550 FPS without the ArmorStand entities (1.9.4 vanilla).

migrated

Can confirm.

NeunEinser

I might have found in the minecraft code what causes it.
The framerate does not drop that much with higher damage values (aka values that refer to models specified further down in the model file) (like /replaceitem entity @e[type=ArmorStand] slot.armor.head diamond_hoe 1 1561 will not cause more lag than the diamond axe).

This code gets run every tick by the renderer (1.9 / MCP 9.24beta)

net.minecraft.client.renderer.block.model.ItemOverrideList.applyOverride()

public ResourceLocation applyOverride(ItemStack p_188021_1_, World p_188021_2_, EntityLivingBase p_188021_3_)
    {
        if (!this.overrides.isEmpty())
        {
            for (ItemOverride itemoverride : this.overrides)
            {
                if (itemoverride.func_188027_a(p_188021_1_, p_188021_2_, p_188021_3_)) //checks if the override matches the item's values
                {
                    return itemoverride.getLocation();
                }
            }
        }

        return null;
    }

This for loop loops 1561 times if it finds the required predicate values in the last step.
Since the renderer calculates the model it should render every game tick new, it might be very CPU heavy if you have many overrides specified.

However, it is not caused by minecraft loading all the different model files. It will not get laggier if you have more complex models applied, it gets only laggier depending on how many overrides are specified.

Please link this in the first post.

bleuthoot

Is this still a thing in 1.10?

migrated

Why was the status of this changed to "Awaiting Response" after Simplius updated the "Affects Version/s" field to include 1.10 in response to bleuthoot's question?

migrated

Why the heck was this resolved as working as intended? Did the developers INTEND to create lag?

migrated

@unknown Sometimes when bugs are resolved as "works as intended" it also could be something like "won't/can'tfix", sometimes currently, sometimes generally.
The way we (ab)used the damage values to display many different models never seemed to be intended by Mojang that way.
Hence the lag is nothing that one can blame onto them, nor one can "force" them to "fix", if it is either unfixable, given the current (bad) state of the code, or if it is basically postponed, if there might be a different system in the future that will let us display bajillions of different models with no (or less) lag (basically a new addition sometime in the future).

My conclusions when looking back the last years are that Mojang tries their best to support mapmakers, which means they are fairly aware what we would love to have, and they will implement many of it (like they already did with other of our wishes) if the code is "ready" for it, and if it's something that can work across all platforms (as they want feature parity).

Believe me, I'm the first one stepping on their toes when I got the feeling anyone "loses" anything with their decisions, it's not as if I wouldn't (constructively) criticize them, but in this case there is nothing to criticize about. I'm confident that there is a good reason that this bug was resolved as "WaI", and that they know how we'd love to have an alternative.

If you want to state your opinion any further and want this bugpost to be reopened, I suggest you go over to Mojira Reddit and open a post where you can write that.

In any case, let's be patient and trust into them that we'll get an alternative }=)
Regards

NeunEinser

@unknown As @unknown already said, it was never intended, that this feature would be used the way that we use it for map making. And there is no easy way to "fix" this bug. The only way to fix it would be to make it event based but that would mean a major rewriting of the code, which they probably will eventually do and as a result of that this bug might as well get "fixed".

You can still reduce lag by not adding unused "spaceholder- models" and by placing often used models at the end (with the highest values).

Besides, if you use the feature as it was intended to be used, it does not create lag. So no, they did not intend to create lag.

MiniDigger

This seems to be properly "fixed" now with 21w05a. https://www.minecraft.net/en-us/article/minecraft-snapshot-21w05a

"Improved performance when using many overrides on an item model"

migrated

Agnes Larsson

Community Consensus

Minecraft 1.9.4, Minecraft 1.10

Retrieved