/give is slow when no target is found
The bug
The /give and /replaceitem commands are slow even when no players are found by the selector. They're especially slow when the specified item has a lot of components, even though there was nobody to even give the item to, so no item should be generated.
How to reproduce
- Download and open the attached world
- Pull the levers next to the command blocks (the two marked with blue concrete are the most important), one at a time
- Observe the server performance for each:
- The one on the left tries to give a sword to a non-existent player, 30,000 times per tick
- The one on the right tries to execute as a non-existent player to give themselves a sword, 30,000 times per tick
Expected behavior
Server performance is identical
Observed behavior
Left command blocks tank the server, right slows it only a bit
2022-09-12, 11:46 PM
2024-04-23, 07:15 PM
2024-04-23, 07:15 PM
5
2
1177623