Skip to content
TheSalt_ edited this page Jan 14, 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


scoreboard-fake-player-missing-hash

Adding # to scoreboard fake players improves performance as they are processed first during selector parsing.

This rule is disabled by default since the performance difference is negligible in singleplayer and you may not want to use it for debugging purposes.

Example:

# Before
scoreboard players set const 100

# After
scoreboard players set #const 100

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

Clone this wiki locally