mojira.dev
MC-132488

Ticking animated textures is very inefficient and can be easily optimized

Currently (in 1.12.2 and 1.13-pre5), all animated textures are updated every tick, which can decrease the framerate by a lot. This can be seen by looking at the 'root.tick.textures' profiler section, which can use up to around 30% of the game loop time with some high resolution texture packs or animations for many blocks.

With very little effort, the code can be changed to tick only visible textures. This is what I did in my mod VanillaFix, and it led to framerate increases of between 10-30% in vanilla Minecraft, and up to 500% in large modpacks with many animated blocks (which applies to vanilla too, a texture pack could decide to have animated textures for every single block, or have very large textures).

Here's how it works (source code here):

I added a needsAnimationUpdate to the TextureAtlasSprite, and changed the TextureMap.update method to only tick the textures which need to be ticked (texture map, texture atlas sprite). That boolean gets set to true in several places, such as the item renderer, block-in-hand renderer, fire-on-entity renderer, etc., and gets set to false each time the animation is ticked.

I also added a visibleTextures set to each CompiledChunk, and the visibleTextures in visible CompiledChunks also get ticked (source). The set is updated every time the chunk is compiled (block renderer, fluid renderer).

This simple optimization has led to large framerate increases for many players, so it would be nice to have it in vanilla 1.13.

Linked issues

Attachments

Comments 12

This is a bug tracker, not for suggestions.

This is a bug, not a suggestion. I am simply suggesting a fix for this bug.

This would leave global-variable-flipping code all over the codebase. Yes it is an improvement, we have to see how to actually do it in a good and maintainable way though 🙂

Iosiv Visokogorskiy

Affects 21w11a

Iosiv Visokogorskiy

Still exist in 1.17 pre 4

2 more comments

I have experienced similar results getting worse as I increase mipmap levels to almost unplayable levels. In addition, it seems it tends to affect AMD gpu's than it does to NVIDIA gpu's. I had a gtx 1050 (with an i7-7700HQ) which did not suffer this problem, but now with my radeon 5500M (and i9-9980HK) it does.

I dug up a little, and it seems a common, documented problem (see https://github.com/FTBTeam/FTB-Revelation-2/issues/366, as an example).

In my opinion, this shouldn't be a low priority issue as it affects greatly the playability of a lot of users and taking in consideration the revamping of the world generation in 1.18, the issue could become more apparent to more players.

Can confirm in 21w40a.

Iosiv Visokogorskiy

Can confirm in 21w44a

Iosiv Visokogorskiy

Affects 1.18 pre 4

Just wanted to add my example of "10-30%" improvement:

[media]

[media]

I used Sodium with all other optimizations disabled

[media]

[media]

Test environment — redstone-ready superflat world even without any placed animated blocks.

Runemoro

(Unassigned)

Confirmed

Platform

Low

Performance

animations, performance

Minecraft 1.12.2, Minecraft 1.13-pre5, Minecraft 1.13-pre8, Minecraft 1.13-pre9, Minecraft 1.13-pre10, ..., 21w40a, 21w44a, 1.18 Pre-release 4, 1.18 Release Candidate 1, 22w06a

Retrieved