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

Ticking animated textures is very inefficient and can be easily optimized


    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.12.2, Minecraft 1.13-pre5, Minecraft 1.13-pre8, Minecraft 1.13-pre9, Minecraft 1.13-pre10, Minecraft 1.13, 1.16.1, 20w29a, 20w30a, 1.16.2 Pre-release 1, 1.16.2 Release Candidate 2, 1.16.2, 1.16.3, 1.16.4 Pre-release 2, 20w46a, 20w49a, 21w03a, 21w05b, 21w11a, 21w19a, 1.17 Pre-release 4, 1.17.1, 21w40a, 21w44a, 1.18 Pre-release 4, 1.18 Release Candidate 1, 22w06a
    • Confirmed
    • Performance
    • Low
    • Platform

      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.

        1. AnimationTick.png
          19 kB
        2. IMG_20230320_213306_198.jpg
          110 kB
        3. IMG_20230320_213306_384.jpg
          142 kB
        4. IMG_20230320_215136_000.jpg
          84 kB
        5. IMG_20230320_215140_022.jpg
          165 kB

            Unassigned Unassigned
            runemoro Runemoro
            39 Vote for this issue
            17 Start watching this issue