/clear command has severe performance drops (increased mspt) after opening the creative mode inventory. The lag persists until you reconnect to the world or clear and re-grant the affected items. Following the reproduction steps below results in roughly an 4.46x increase in mspt.
This doesn't heavily affect finalized maps played strictly in survival/adventure mode, but it hinders map developers during the creation process.
For counting items, /execute if items can be used as a temporary workaround.
Steps to Reproduce:
Create a new void superflat world.
Change the gamemode to survival.
Run the following command to fill the inventory with items:
/loot replace entity @p contents loot {pools:[{rolls:1,entries:[{type:tag,items:"#logs"}]}],modifier:[{type:set_count,count:64},{type:set_custom_data,tag:{a:1,b:2b,c:{c1:aaaaaaaaaaaaaaaaaa,c2:[a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a]}}}]}Set up a repeating command block to count items 1024 times per tick using
/clear.
(For example, summon at least 4 entities into the world and put the following command into the command block):/execute rotated as @e[limit=4] rotated as @e[limit=4] rotated as @e[limit=4] rotated as @e[limit=4] rotated as @e[limit=4] run clear @a * 0Change the gamemode to creative.
Open and close the inventory in creative mode, and observe the sharp increase in lag (with the F3+2 graph).
Linked issues
relates to 2
Attachments
Comments 6
Can confirm, but what is the actual impact of this on mapmakers? When is it necessary to actually run such a command?
Thank you for your report!
After consideration, the issue is being closed as Invalid.
This report does not describe a bug.
Quick Links:
π Bug Tracker Guidelines β π¬ Community Support β π§ Mojang Support (Technical Issues) β π§ Microsoft Support (Account Issues)
π Project Summary β βοΈ Feedback and Suggestions β π Game Wiki
Thanks for confirming!
What counts as 'actual impact' is a bit tricky here. People who are aware of this issue would end up moving to more complex workarounds just to avoid using
/clearin their datapacks, and those who don't know about it would be left with a mysterious performance degradation that triggers whenever they do something in creative.If you are referring to the 1024 repetitions, that is not a strict requirement to trigger the bug. It was just used as an example to make the performance difference clearly visible. Even if these commands aren't run in an artificial loop like that and are instead spread across various things, they are still affected. The main point is that this is an abnormal increase of lag, and less lag is always better.
/clearis widely used for implementing basic mechanics like detecting items, consuming arrows/resources, or banning illegal items. The more features like this a project has, the worse the impact gets. Multiplied checks from using the "@a" selector with multiple players is also a contributing factor.
I agree that this isnβt optimal, and honestly Iβm not sure why this was called Invalid- I would have expected at least Wonβt Fix. But this space is very much what predicates are meant to be used for, and now that they can be specified inline (so they are usable in the context of command blocks only) I think it makes sense for Mojang not to place much importance on the performance of alternative solutions.
That's true for checking items, but /clear is still necessary when actually removing items from an inventory. (I didn't include that in the reproduction setup because I thought constantly clearing and refilling items might bias the benchmark.) Using it with execute store result to get a numerical value for item amount is also common, though that's at least easier to work around now with if items.
Also, no worries! There was a hint on the Minecraft Commands Discord that a fix might actually be possible. It's not guaranteed yet, but it seems promising.
Thank you for helping us improve Minecraft! We saved your files: