Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-269212

Worse performance with "execute unless tag" compared to "execute if !tag"

XMLWordPrintable

    • Icon: Bug 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:

      1. Install the attached data pack in your world
      2. /reload
      3. Place a repeating command block with "execute as @p run function test:if_not"
      4. Observe the MSPT in the F3 menu (Also try giving yourself the "Test" tag with "/tag @s add Test")
      5. Change the command to "execute as @p run function test:unless"
      6. 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.

            Unassigned Unassigned
            SilicatYT SilicatYT
            Votes:
            6 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: