Mojira Archive
MC-259563

Command exception messages are unnecessarily created and stringified during function execution

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.

Invalid

intsuc

2023-01-30, 10:56 AM

2023-02-01, 08:03 AM

2023-01-31, 08:27 AM

1

5

Confirmed

Commands, Performance

1.19.3, 23w04a

-