mojira.dev
MC-307147

Performance regression: opening the creative mode inventory menu whilst saved hotbars are loaded and have a lot of data causes a lagspike

Unlike bugs I’ve reported before this isn’t an exploit. Wow, I know! I discovered this one while actually working on a mod to improve the saved hotbar system.

The Bug

1.20.5+ introduced a performance regression which cause lagspikes whenever you open the creative inventory menu with saved hotbars containing a metric ton of data, which occurs even after the game loads the hotbars into memory. The lagspike associated with loading the hotbar is a regression of its own (introduced in 1.13) and is not the same lagspike as this.

The lagspike is caused by a section of code in the selectTab method from CreativeModeInventoryScreen, which is responsible for setting up the contents of whatever tab somebody selected. This gets called both when you click a tab and also whenever you open the creative mode inventory screen. After the game gets the HotbarManager, it iterates through each hotbar row individually and converts each item from a Dynamic instance to an ItemStack using Hotbar’s load method. However, the results of this are never cached and as such every time you open the creative mode inventory menu, the game has to do this conversion process over and over again. This would be fine if it weren’t for the fact that Hotbar’s load method is actually fairly computationally expensive when you have items with a lot of data on them.

Judging from the facts that this issue wasn’t present in older versions of the game, was introduced in the very same version that completely overhauled how a lot of data got loaded and saved, and happens to also co-exist with another lagspike caused by I/O operations, I believe this is an unintentional bug/performance regression and not a deliberate decision. The only reason I noticed it was because the mod I wrote uses a page system to extend the overall capacity to ludicrous levels and the way I implemented it intentionally calls selectTab whenever somebody switches to another hotbar file to refresh the page.

The Solution

The ideal solution (or at least, the solution I ended up going with while developing my mod) was to add some extra code to Hotbar which simply caches the result of converting the Dynamics to ItemStacks the first time it is run and returns that cached result on subsequent runs, updating it only when necessary (such as when you save to that particular hotbar).

Steps to Reproduce

  1. Download the hotbar.nbt file from https://files.catbox.moe/j3c8yh.nbt (I have to host it this way because the attachment uploader on this website sucks and just hangs trying to upload it), rename it to hotbar.nbt, and copy it to your .minecraft folder

  2. Launch the game

  3. Open any world with creative mode access

  4. Press F3+2 to show the FPS profiler

  5. Open the creative mode menu and navigate to the Saved Hotbars tab

  6. Close the creative mode menu with the tab still opened and re-open it.

  7. Notice how a lagspike consistently occurs every time you do this

Linked issues

Attachments

Comments 5

Hi!
Thank you for your report! 

Could you please provide more details.

  • Could you please record a video of the issue and upload it?

  • Does the issue also occurs without hotbar nbt file?

  • Could you please include details about your device and system specifications (RAM, CPU, GPU)?

Quick Links
📓 Issue Guidelines – 💬 Mojang Support – 📧 Suggestions – 📖 Minecraft Wiki

Howdy!

Here is a video of the issue in action along with a demonstration of my proposed fix: https://youtu.be/KO2EdpD_MKM

I mentioned a proposed fix to the issue in the video. The source code of which can be found here: https://github.com/VideoGameSmash12/Librarian/blob/8ce374ae534b112f2f23d5ffd13c81f2e086d252/26.1/src/main/java/me/videogamesm12/librarian/v26_1/mixin/HotbarMixin.java

Here is a copy of the hotbar.nbt I used in my demonstration video: https://files.catbox.moe/oj8to0.nbt

The conversion process happens regardless of the state of the hotbar.nbt file, but it is required that you have a lot of saved hotbar data in memory. A blank hotbar.nbt file will not produce any sufficiently noticeable lagspikes.

Here are my system specifications:

  • CPU: AMD Ryzen 7 7800X3D

  • GPU: AMD Radeon RX 7800 XT

  • RAM: 64 GB DDR5

Since it lagspikes on my system even with such specifications, this also carries the implication that the lagspikes are greater on weaker systems..

Cheers.

Personally I cannot reproduce this

Actually, you are, but it’s to a much less severe degree. Notice the red spikes that happen every time you open the inventory with that tab open.

I don't see any spikes that are distinguishable from noise, and nothing anywhere near the very noticeable spike I encountered when I first launched the game and opened the saved hotbar tab.

VideoGameSmash12

(Unassigned)

Unconfirmed

(Unassigned)

26.1

Retrieved