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

Setting render distance to values >8 chunks freezes the game for >1 second (minutes for higher values)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 19w46a
    • 19w39a, 19w40a, 19w42a, 19w44a, 19w45b
    • Community Consensus
    • Performance, Rendering
    • Very Important

      The bug

      This already happened in earlier versions, but ONLY when VBOs are disabled (that only happened on some GPU drivers, for example linux intel GPU drivers). That option has been removed in one of recent versions so this shouldn't be an issue anymore.

      I can reproduce it reliably every time now immediately after entering the world, but in the initial few tests, it appeared to happen only after a while of flying around the world (I don't know what actually triggered it).

      This was not an issue in 19w37a, it appears to be introduced in 19w38a

      It seems to coincide with MC not displaying GPU vendor and opengl version properly (screenshots showing this attached, it does show up correctly in crash report output).

      Running visualvm sampler shows that all of the time is spent in RenderSystem.glGenBuffers and subsequently GL15C.nglGenBuffers (sampler snapshot attached). As far as my understanding goes, this is very likely caused by requesting gl buffers separately for each render section, instead of all at once.

       

      Update: opengl version and vendor not being shown is a completely separate thing that doesn't affect anything. Appearing in the same snapshot was a coincidence.


      The reason

      After a bit of testing in mod development environment with latest snapshot, I was able to find a fix/workaround in code in GlStateManager. It's not exactly the best solution, but works really well in practice and requires very little code changes:

       

          private static final int GENBUFFERS_BATCH = 2048;
          private static IntBuffer BUFFERS;
      
          public static int genBuffers() {
              RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
              if (BUFFERS == null || !BUFFERS.hasRemaining()) {
                  if (BUFFERS == null) {
                      BUFFERS = BufferUtils.createIntBuffer(GENBUFFERS_BATCH);
                  }
                  BUFFERS.rewind();
                  GL15.glGenBuffers(BUFFERS);
                  BUFFERS.rewind();
              }
              return BUFFERS.get();
          }
      

      This confirms that the issue is the huge amount of glGenBuffers calls, but it's still unclear to me why it's a performance issue to begin with, especially with glDeleteBuffers not being an issue at all.

      A good solution would be to allocate and delete all the chunk buffers in one glGenBuffers call but that doesn't work nicely with the way this code is written.

       -- 

      I also verified that this code didn't change in any significant way even since 1.12.2 so I really have no idea what has changed here that suddenntly makes this code path so much slower.

       

      After more debugging, this is the real reason (full explanation of how I found it in comments):

      Minecraft is binding already deleted VertexBuffers, which it internally assigns an ID of -1 to. This ends up changing mesa driver internal state in a way that always triggers a very slow code path for glGenBuffers.

       

       

        1. 19w37a_hasOpenglVersion.png
          408 kB
          Bartosz Skrzypczak
        2. 19w40a_noOpenglVersion.png
          370 kB
          Bartosz Skrzypczak
        3. 2019-11-11_08.12.08.png
          372 kB
          Fabian Röling
        4. 2019-11-11_08.12.11.png
          410 kB
          Fabian Röling
        5. 2019-11-11_08.12.55.png
          375 kB
          Fabian Röling
        6. 2019-11-11_08.12.57.png
          410 kB
          Fabian Röling
        7. 2019-11-11_08.12.59.png
          412 kB
          Fabian Röling
        8. 2019-11-11_08.13.02.png
          412 kB
          Fabian Röling
        9. 2019-11-11_08.13.06.png
          412 kB
          Fabian Röling
        10. 2019-11-11_08.13.10.png
          415 kB
          Fabian Röling
        11. 2019-11-11_08.13.16.png
          415 kB
          Fabian Röling
        12. 2019-11-11_08.13.24.png
          416 kB
          Fabian Röling
        13. 2019-11-11_08.13.34.png
          411 kB
          Fabian Röling
        14. 2019-11-11_08.13.43.png
          421 kB
          Fabian Röling
        15. 2019-11-11_08.13.55.png
          417 kB
          Fabian Röling
        16. 2019-11-11_08.14.15.png
          409 kB
          Fabian Röling
        17. 2019-11-11_08.14.44.png
          425 kB
          Fabian Röling
        18. 2019-11-11_08.15.08.png
          408 kB
          Fabian Röling
        19. 2019-11-11_08.15.50.png
          410 kB
          Fabian Röling
        20. 2019-11-11_08.16.31.png
          406 kB
          Fabian Röling
        21. 2019-11-11_08.17.23.png
          409 kB
          Fabian Röling
        22. 2019-11-11_08.18.27.png
          412 kB
          Fabian Röling
        23. 2019-11-11_08.19.47.png
          413 kB
          Fabian Röling
        24. 2019-11-11_08.21.25.png
          396 kB
          Fabian Röling
        25. 2019-11-11_08.23.12.png
          414 kB
          Fabian Röling
        26. 2019-11-11_08.25.12.png
          409 kB
          Fabian Röling
        27. 2019-11-11_08.27.35.png
          399 kB
          Fabian Röling
        28. 2019-11-11_08.30.15.png
          420 kB
          Fabian Röling
        29. 2019-11-11_08.33.22.png
          405 kB
          Fabian Röling
        30. 2019-11-11_08.36.51.png
          414 kB
          Fabian Röling
        31. 2019-11-11_08.40.58.png
          415 kB
          Fabian Röling
        32. 2019-11-11_08.45.41.png
          416 kB
          Fabian Röling
        33. 2019-11-11_22.24.44.png
          412 kB
          Fabian Röling
        34. 2019-11-11_22.30.43.png
          407 kB
          Fabian Röling
        35. forced_crash_19w37a.txt
          2 kB
          Bartosz Skrzypczak
        36. forced_crash_19w40a.txt
          3 kB
          Bartosz Skrzypczak
        37. sampler_snapshot.nps
          5 kB
          Bartosz Skrzypczak

            fry [Mojang] Georgii Gavrichev
            Barteks2x Bartosz Skrzypczak
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: