Skip to content
TheSalt_ edited this page Apr 29, 2026 · 13 revisions

This page documents all optimization rules provided by Datapack Optimization Helper.

Table of Contents

Execute

Target Selector

Code Analysis

Others


execute-run-redundant

execute run <command> at the start of a line can be simplified to just <command>.

Example:

# Before
execute run say hello

# After
say hello

Auto-fix: Yes


execute-run-redundant-nested

run execute run pattern can be simplified to just run.

Example:

# Before
execute as @a run execute run say hello

# After
execute as @a run say hello

Auto-fix: Yes


execute-run-redundant-run-execute

run execute in the middle of an execute chain is redundant and can be removed.

Example:

# Before
execute as @a run execute if entity @s[tag=foo] run say hello

# After
execute as @a if entity @s[tag=foo] run say hello

Auto-fix: Yes


execute-as-s-redundant

as @s is redundant because the executor is already the current entity.

Example:

# Before
execute as @s run say hello

# After
say hello

Auto-fix: Yes


execute-duplicate

Duplicate execute subcommands can be merged.

Example:

# Before
execute at @s at @s run setblock ~ ~ ~ stone

# After
execute at @s run setblock ~ ~ ~ stone

Auto-fix: Yes


execute-unnecessary

Detects unnecessary execute subcommands that have no effect.

Example:

# Before
execute positioned 0 0 0 at @s run setblock ~ ~ ~ stone

# After
setblock ~ ~ ~ stone

Auto-fix: Yes


execute-group

Grouping execute commands into a function improves performance.

Example:

# Before
execute as @a run say 1
execute as @a run say 2

# After
execute as @a run function namespace:grouped_tasks

# grouped_tasks.mcfunction
say 1
say 2

Auto-fix: No


execute-as-if-entity-s-merge

as <selector> if entity @s pattern can be merged into as.

Example:

# Before
execute as @a if entity @s[tag=foo] run say hello

# After
execute as @a[tag=foo] run say hello

Auto-fix: Yes


execute-as-if-entity-s-convert

Suggests merging when as <selector> if entity @s pattern has arguments in selector.

Example:

# Before
execute as @a[scores={foo=1}] if entity @s[scores={bar=2}] run say hello

# After
execute as @a[scores={foo=1,bar=2}] run say hello

Auto-fix: Yes


target-selector-no-type

Using @e without a type argument selects all entities, causing performance degradation.

This rule does not support quick fix.

Example:

# Before
execute as @e run say hello

# Recommended
execute as @e[type=zombie] run say hello

Auto-fix: No


target-selector-no-dimension

Selectors without dimension constraints will search across all dimensions, causing performance degradation.

Having x, y, z, dx, dy, dz, or distance limits the search dimension, improving speed.

[!NOTE] > dx, dy, dz, distance also limit chunks, providing slightly better performance.

Example:

# Before
execute as @a[tag=foo] run say hello

# After
execute as @a[distance=0..,tag=foo] run say hello

Auto-fix: Yes


target-selector-type-order

Placing the type argument at the end is slightly faster.

Note

When checking selectors, the game first filters entities by type, then checks the remaining arguments against those entities. If type is placed at the end, redundant checks can be minimized. For more details, see here.

Example:

# Before
execute as @e[type=pig,tag=foo] run say hello

# After
execute as @e[tag=foo,type=pig] run say hello

Auto-fix: Yes


unreachable-code

Code below an always-executed return will never run.

Example:

return 1
say this code will never run

Auto-fix: No


unreachable-condition

Detects conditions that can never be true based on previously set score values.

Example:

# Score is set to 5
scoreboard players set #foo obj 5
# The condition below can never be true (5 != 10)
execute if score #foo obj matches 10 run say hello
# Score is reset
scoreboard players reset #foo obj
# Reset scores don't exist, so if condition always fails
execute if score #foo obj matches 1 run say hello

Auto-fix: No


always-pass-condition

Detects conditions that are always true based on previously set score values.

Example:

# Score is set to 5
scoreboard players set #foo obj 5
# The condition below is always true (5 matches 5)
execute if score #foo obj matches 5 run say hello
# Score is set to 5
scoreboard players set #foo obj 5
# The condition below is always true (5 is not 10)
execute unless score #foo obj matches 10 run say hello

Auto-fix: No


infinite-recursion

Detects functions that may cause infinite recursion.

Example:

function namespace:self

Auto-fix: No


macro-function-without-with

Detects calls to a macro function (a function containing $-prefixed lines) without a with clause or {...} arguments.

Calling a macro function without arguments will silently skip execution of the function.

Example:

# greet.mcfunction (macro function)
$say Hello, $(name)!
# Before
function namespace:greet

# After
function namespace:greet {name:"world"}
# or
function namespace:greet with storage namespace:data

Auto-fix: No


scoreboard-fake-player-missing-hash

Using # when using scoreboards improves performance because it is processed first during selector parsing.

The code that processes the target part of the scoreboard in Minecraft is as follows:

if (text.equals("*")) {
    return (sender, wildcard) -> {
        Collection<ScoreHolder> results = (Collection<ScoreHolder>)wildcard.get();
        if (results.isEmpty()) {
            throw ERROR_NO_RESULTS.create();
        } else {
            return results;
        }
    };
} else {
    List<ScoreHolder> nameOnlyHolder = List.of(ScoreHolder.forNameOnly(text));
    if (text.startsWith("#")) {
       return (sender, wildcard) -> nameOnlyHolder;
    } else {
       try {
          UUID uuid = UUID.fromString(text);
          return (sender, wildcard) -> {
             MinecraftServer server = sender.getServer();
             ScoreHolder firstResult = null;
             List<ScoreHolder> moreResults = null;
             for (ServerLevel level : server.getAllLevels()) {
                Entity entity = level.getEntity(uuid);
                if (entity != null) {
                   if (firstResult == null) {
                      firstResult = entity;
                   } else {
                      if (moreResults == null) {
                         moreResults = new ArrayList();
                         moreResults.add(firstResult);
                      }
                      moreResults.add(entity);
                   }
                }
             }
             if (moreResults != null) {
                return moreResults;
             } else {
                return firstResult != null ? List.of(firstResult) : nameOnlyHolder;
             }
          };
       }
    // ...

Because of the if (text.startsWith("#")) part, if the target name starts with #, the check for UUIDs, target selectors, etc. is skipped and it returns immediately, making performance slightly faster.

Source Code

The performance difference is not significant in singleplayer, and it is disabled by default as you may choose not to use it for debugging purposes.

Example:

# Before
scoreboard players set const 100

# After
scoreboard players set #const 100

Auto-fix: No


scoreboard-divide-by-zero

Detects division by zero in scoreboard operations.

Example:

scoreboard players set #zero obj 0
scoreboard players operation #foo obj /= #zero obj

Auto-fix: No


scoreboard-overflow

Detects scoreboard values that exceed the 32-bit integer range (-2,147,483,648 to 2,147,483,647).

Example:

scoreboard players set #foo obj 2000000000
scoreboard players add #foo obj 2000000000
# #foo = -294967296

Auto-fix: No


return-run-duplicate

Detects unnecessarily duplicated return run patterns.

Example:

# Before
return run return run function namespace:foo

# After
return run function namespace:foo

Auto-fix: Yes


nbt-items-use-if-items

Using if items is more performant than checking items via NBT.

Example:

# Before
execute if data entity @s Inventory[{Slot:0b,id:"minecraft:diamond"}] run say hello

# After
execute if items entity @s container.0 minecraft:diamond run say hello

Auto-fix: No


naming-convention

Warns when scoreboard objective, tag, or team names do not match the configured pattern.

Configurable per-project via namingConvention.scoreboardObjective / namingConvention.tag / namingConvention.team in datapack.config.json.

Supported patterns

Pattern
camelCase
snake_case
PascalCase
kebab-case
SCREAMING_SNAKE_CASE
Regex

Example:

// datapack.config.json
{
  "namingConvention": {
    "scoreboardObjective": "snake_case",
    "tag": "snake_case",
    "team": "snake_case",
  },
}
# Before (camelCase does not match the snake_case pattern)
scoreboard objectives add myObjective dummy
tag @s add myTag
team add myTeam

# After
scoreboard objectives add my_objective dummy
tag @s add my_tag
team add my_team

Besides the patterns above, you can also specify with a regular expression:

{
  "namingConvention": {
    "scoreboardObjective": "^[a-z][a-z0-9_]*$",
  },
}

Auto-fix: No