Appearance
Build options
Build options change how helix writes the pack, not what it does: optimizer passes and debug helpers.
ts
// helix.config.ts
export default defineConfig({
name: "game",
version: v26_3,
entry: "src/pack.ts",
out: { datapack: "out" },
debug: { comments: true },
optimize: { inline: false },
});| Option | Default | Does |
|---|---|---|
debug.sources | off | Maps each command to the TS line that emitted it |
debug.comments | off | Also writes # <file>:<line> above commands. Implies sources |
optimize.inline | on | Folds one-command private functions, and ones called from a single plain function line, into their callers |
optimize.unroll | on | Writes fixed-count loops out in place when the copies are small |
optimize.group | on | Moves lines sharing an execute prefix into one call |
optimize.reorderForks | on | Lets grouping run a forked prefix whole per entity |
optimize.inferTypes | on | Adds type= to selectors whose tags only one entity type gets |
optimize.internReads | on | Interns /compute score reads used more than once |
optimize.dedupe | on | Merges private functions with identical bodies into one file |
optimize.splitChains | on | Searches an if/elif chain of 16+ branches on one score by range |
layout | "split" | Private functions under zzzprivate/, or "beside" their owner |
TIP
dp.keep(fn) keeps one function out of inlining, so it stays a file you can find by name in reports and profiles.
Find the line behind a command
debug.comments writes the source line above each run of commands.
text
# src/pack.ts:12
scoreboard players add @s game 1
# src/pack.ts:13
say tick!debug.sources alone keeps the files clean. helix report then shows a ↳ line under each warning, and the build writes helix-sources.json next to the pack.
TIP
In helix.config.ts, debug applies to dev builds only, so helix build --prod always ships without comments.
Turn an optimization off
Turn a pass off to see what it changed, or to rule it out when output looks wrong.
ts
import { Datapack, v26_2, Selector } from "helix";
const dp = new Datapack("game", v26_2, undefined, {
optimize: { inline: false, group: false },
});
dp.createFunction("tick").build(() => {
Selector.allPlayers().forEach((p) => p.say("hi"));
});Compiled output - the real files helix emits for the code above:
txt
execute as @a at @s run say hijson
{
"values": [
"game:tick"
]
}txt
{
"pack": {
"description": "game\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}WARNING
reorderForks assumes no entity depends on another's order inside a forked execute. Turn it off if your per-entity lines read each other's state.
Long if/elif chains
An if/elif chain checks its branches in order and stops at the first match, so the last of 100 branches costs 100 checks. When every branch tests the same score and no two ranges overlap, splitChains searches by range instead: check the half, then the half of that, down to 8 branches per function.
text
# f.mcfunction
execute if score #x o matches 0..49 run return run function p:zzzprivate/f/if_0_split_14
execute if score #x o matches 50..99 run return run function p:zzzprivate/f/if_0_split_29| Matching branch of 100 | Flat chain | Split |
|---|---|---|
| 99th | 27 us | 4 us |
| 50th | 14 us | 3 us |
| 3rd | 1.5 us | 3 us |
Times are per call, on a 26.3 server. Chains under 16 branches stay flat, since they're as fast that way. Turn it off if nearly every call matches one of the first few branches.
Set them without a config
Pass the same options as the fourth Datapack argument: new Datapack(name, version, target, { debug, optimize, layout }).
Try them in the playground
The playground's build menu toggles debug.comments and each optimize pass. There, comments show as line N labels; click one to jump to its line.
See also
- Getting started
- Helix:
helix reportand the other commands