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

Command exception messages are unnecessarily created and stringified during function execution

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • None
    • 1.19.3, 23w04a
    • None
    • Confirmed
    • Commands, Performance

      The bug

      As with MC-159633, an unused component is created when a command fails during function execution. Furthermore, the component is stringified to be passed to the Exception constructor. This imposes a constant overhead for typical command failures and a linear overhead for some command failures.

      Example

      The following command takes a linear time for the deep size of the target NBT on failure because it creates an exception message "Expected list, got: …" where … is the stringified target NBT.

      data modify storage _ _ append value 0b

      Code analysis

      If a command fails, a CommandSyntaxException is eventually created in most cases.

      com.mojang.brigadier.exceptions.CommandSyntaxException
          public CommandSyntaxException(final CommandExceptionType type, final Message message) {
              super(message.getString(), null, ENABLE_COMMAND_STACK_TRACES, ENABLE_COMMAND_STACK_TRACES);
              this.type = type;
              this.message = message;
              this.input = null;
              this.cursor = -1;
          }
      

      The created component is converted to a string in message.getString(), but that string and the component are never used during normal function execution.

            Unassigned Unassigned
            intsuc intsuc
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: