-
Bug
-
Resolution: Unresolved
-
None
-
1.20.4, 24w10a, 1.21 Release Candidate 1, 1.21
-
None
-
Confirmed
-
Performance
Example video (1.21rc-1): https://youtu.be/TByzwsQTj_A
Note:
I will be referencing "execute if entity @s[tag=Test]" as "function test:if" and "... if entity @s[tag=!Test]" as "test:if_not". Same for "unless". These are the names of the functions in the example datapack that include their respective command copy pasted 40,000 times.
How to reproduce:
- Install the attached data pack in your world
- /reload
- Place a repeating command block with "execute as @p run function test:if_not"
- Observe the MSPT in the F3 menu (Also try giving yourself the "Test" tag with "/tag @s add Test")
- Change the command to "execute as @p run function test:unless"
- Observe the MSPT again, and again give and remove the "Test" tag to see how the MSPT changes
Observed result:
You'll see that when running the test:unless function, the MSPT are lower than with test:if_not when you don't have the tag, but way higher if you do have the tag
(See attached images)
If the executing entity doesn't have the "Test" tag, "test:unless" is faster than its "test:if_not" counterpart.
![]()
However, if the executing entity has the "Test" tag, "test:unless"'s performance impact skyrockets and is unexpectedly almost twice as slow.
This means that "if" and "if not" will be faster than the "unless" subcommand that was specifically made for this.
![]()
Expected result:
"test:if" and "test:unless_not" behave the same and should thus have a comparable performance impact
"test:if_not" and "test:unless" behave the same and should thus have a comparable performance impact
TLDR:
If the condition of the subcommand fails, there's a performance cost.
But specifically for "execute unless", the performance cost when it fails is so big that using "execute if not" becomes almost twice as fast.