Mojira Archive
MCM-1795

Memory leaks and high memory usage caused by unique entity tags

Partner Rank:
2

Partner Team Reporting:
Everbloom Games

Verification builds:
1.21.10

Summary:
Tags on entities can cause memory leaks, or at the very least abnormally high memory usage. Every unique tag ever added to an entity since the server starts is tracked, and kept in an internal list. This list never shrinks, even if tags are removed! This can result in more and more memory being allocated and never freed until the world is reopened or the server is restarted.
We suspect this may be related to the autocomplete functionality of tags in commands, although autocomplete appears to only show tags that currently exist in the world.

Impact:

This was reported to us last year, as a slow-growing memory leak in our content (the Minecraft D&D map), and only after a lot of investigation did we find it was an inefficiency with how Minecraft uses tags. We did eventually replace the particularly problematic usage of tags with scoreboards, but the problem still stands: content can use a very significant variety of unique tags, even if not present all at once, and performance can be negatively impacted by tags the longer the player plays for.

Repro Steps:

  1. Open Minecraft in a Release build of the game (with ImGui functionality).
  2. Open the provided world.
    This world contains a repeating command block and an armor stand. When the command block is powered, a script will add AND remove 20 random unique tags on that armor stand, every tick (400 random tags per second).
  3. Open the Memory view in the ImGui debug screen: Search Window > Memory > Memory, and expand the Memory Tracking window
  4. Switch the lever on (to the down position) and observe the memory tracked under "Unknown" (colored red, at least in 1.21.10)
  5. Run `/tag @e list` in chat to prove there are no tags on any entities.

Observed Results:

Memory usage under Unknown starts growing rapidly while the lever is powered (it seems to grow exponentially as well?)
This is despite there being no build-up of tags on any entities, since the tags are removed immediately after being added.

Expected Results:

Memory usage should remain stable, not growing unbounded.

Regression Build:

Unknown.

Screenshots / Videos Attached:

Yes.

Unresolved

Energyxxer

2024-07-10, 10:44 PM

2024-07-11, 07:32 PM

0

0

-

-