Skip to content

Latest commit

 

History

History
125 lines (106 loc) · 7.14 KB

File metadata and controls

125 lines (106 loc) · 7.14 KB

mcfunction Backend Notebook

This directory answers one backend question per file: how a language operation can actually be represented and executed by a Minecraft Java data pack.

The target is Minecraft Java 26.2, data-pack format 107.1. The commands discussed here are not assumed to be equally fast merely because they occupy the same number of lines. Minecraft counts execution stages, function invocations, and forked contexts separately; a single execute as @e line can therefore be much more expensive than several scalar scoreboard commands.

Evidence labels

  • Documented: described by Mojang release notes.
  • Derived: follows from documented command behavior, but the composition is our own design.
  • Candidate: plausible compiler strategy that needs a real-server test.
  • Measured: observed on the target vanilla server with the experiment recorded.

Many executable recipes still need to become automated 26.2 integration tests. OpenJDK 25.0.3 and the official vanilla 26.2 server are now available for doing so; the command-limit, scheduling, native range, and float-conversion claims have received direct server tests.

Questions answered so far

The reusable vanilla research fixture for the three new inventories lives under fixtures/native-primitives-26.2. Run its world on an isolated port; it is research input, not compiler runtime code.

Stage 8 turns the score/NBT and synchronous execution research into compiler evidence. Scalar recursive SCCs use compiler-private command-storage tail fields with Bool stored as byte and Int32 as int; acyclic and serial selector children reuse static scores. The measured behavior, abnormal-termination contract, and exact compiler protocol are recorded in ../compiler/stage-8-completion-audit.md.

Initial backend rule

A source type does not imply one runtime representation. The compiler should track a set of legal representations and select one using whole-region usage information. For example:

  • a hot mutable integer normally belongs in a scoreboard;
  • an integer used only as command NBT can remain an NBT integer;
  • a numeric value used as a float only at an output boundary can be converted during execute store;
  • a newly constructed list should be materialized once, not appended element by element;
  • a Text value should normally remain a structured text component rather than be flattened into a string;
  • a bounded dynamic array can use specialization or dispatch, while a truly dynamic array may justify a macro-indexed NBT path.

This means representation selection, scalar replacement, batching, and loop specialization are core compiler passes—not library afterthoughts.

Cost dimensions to record

Every candidate implementation should eventually be measured along at least these dimensions:

  1. pre-parsed command executions;
  2. execute stages;
  3. contexts created by selector forks;
  4. function invocations;
  5. macro cache hits and misses;
  6. scoreboard reads/writes;
  7. command-storage/NBT reads, writes, copies, and list shifts;
  8. temporary commands needed to bridge representations;
  9. generated pack size and load/reload time;
  10. peak commands and wall time per tick.

Mojang explicitly documents that macro lines are reparsed after substitution and that repeated argument sets may be cached. Mojang also documents that command-chain accounting includes individual command contexts, execute stages, and function invocations. These facts are the starting point for the cost model, not a complete performance model.

Primary references