[PR #5686] [MERGED] perf(commands): /fill matches its filter once per state and passes over blocks already placed #6435

Closed
opened 2026-11-03 06:20:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5686
Author: @Stink-O
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: faster-fill


📝 Commits (2)

  • 4a7c664 fill: skip blocks that are already the block, match the filter once per state
  • 047b17f Merge main into #5686

📊 Changes

1 file changed (+20 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game/commands.rs (+20 -3)

📄 Description

🤖 Opened by Stink-O's AI agent (Claude Code, Claude Opus 5.5), not by Stink-O personally.

What and why

Fixes #5684. Found while porting Orbital Laser to native hooks (tracking:
#5727), whose craters fill big regions; any large /fill gets cheaper.

cmd_fill visits up to 32,768 blocks, usually of a handful of states. Two changes, with the same results:

  • The replace <filter> predicate is matched once per block state for the whole fill. Today a tag filter does a
    registry lookup and a tag-set lookup per block.
  • In the plain modes (not destroy, hollow or outline), a block that's already the fill's state is skipped
    before the filter. place_state returned false for it anyway, so it was never counted.

Counts, feedback, keep, strict, block entities and commands.fill.failed are unchanged.

Kind

  • perf

Vanilla reference

FillCommand.fillBlocks / BlockInput.place: a state equal to the current one is no change, so it isn't counted.
Harnesses: command_exec (its corpus, tools/command_exec_corpus.py, runs /fill in every mode, with and without
replace) and fill_layer.

Other projects' code

None from other projects. Ported from the author's own fork of Horizon (Stink-O/horizon, MIT):
242b45037.

How it was tested

  • Measured through Horizon's own headless command runner (HORIZON_COMMAND_SCRIPT, as
    tools/test_command_exec_parity.py uses it), fast profile, with the same world (seed 1, radius 4) on main
    (5edb339a7) and on this branch. The script times a run with 1 fill and a run with 1,001, three of each, and takes
    the fastest. The difference over 1,000 is one fill. Each fill is a 32×32×32 box of stone 20 blocks over the
    player:

    Case main this PR
    fill ~ ~20 ~ ~31 ~51 ~31 stone replace #minecraft:logs over stone (the filter matches nothing) 3.26 ms 0.51 ms
    fill ~ ~20 ~ ~31 ~51 ~31 stone over stone (every block already stone) 0.53 ms 0.08 ms

    The script is ~50 lines of Python (below). Run it from a checkout with .local prepared:
    python3 fill_bench.py target/fast/horizon-client 1000.

    fill_bench.py
    #!/usr/bin/env python3
    """Time /fill on a Horizon checkout through its headless command runner (HORIZON_COMMAND_SCRIPT, as
    tools/test_command_exec_parity.py runs commands): the same world twice, once with 1 fill and once with 1 + N, and
    the difference over N is one fill's cost. Run from a Horizon checkout with .local prepared:
    
        python3 fill_bench.py BINARY [N]
    
    Cases (each a 32x32x32 box 20 blocks over the player, first made stone):
      replace: `fill ... stone replace #minecraft:logs` over stone (the tag filter matches nothing; the fill fails)
      plain:   `fill ... stone` over stone (every block already the fill's)
    """
    import json
    import subprocess
    import sys
    import tempfile
    import time
    from pathlib import Path
    
    sys.path.insert(0, str(Path.cwd() / "tools"))
    import lab  # noqa: E402
    
    BINARY = Path(sys.argv[1]).resolve()
    N = int(sys.argv[2]) if len(sys.argv) > 2 else 1000
    BOX = "~ ~20 ~ ~31 ~51 ~31"
    CASES = {"replace": f"fill {BOX} stone replace #minecraft:logs", "plain": f"fill {BOX} stone"}
    
    
    def run(commands):
        with tempfile.TemporaryDirectory() as d:
            d = Path(d)
            script = [{"op": "settle"}, {"op": "cmd", "cmd": f"fill {BOX} stone", "record": False}]
            script += [{"op": "cmd", "cmd": c, "record": False} for c in commands]
            (d / "script.jsonl").write_text("".join(json.dumps(op) + "\n" for op in script))
            env = lab.game_env(HORIZON_SERVER_THREAD=1, HORIZON_PLAYER_NAME="Player",
                               HORIZON_COMMAND_SCRIPT=d / "script.jsonl", HORIZON_COMMAND_OUTPUT=d / "out.jsonl",
                               HORIZON_API_DISCOVERY="http://127.0.0.1:9/")
            start = time.perf_counter()
            subprocess.run([BINARY, "--resources", lab.RESOURCES, "--world", "bench", "--seed", "1", "--radius", "4"],
                           cwd=d, env=env, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
            return time.perf_counter() - start
    
    
    for name, command in CASES.items():
        # Alternate short and long runs so drift hits both; keep the fastest of each.
        short, long = [], []
        for _ in range(3):
            short.append(run([command]))
            long.append(run([command] * (N + 1)))
        per = (min(long) - min(short)) / N * 1000
        print(f"{name}: {N} fills took {(min(long) - min(short)) * 1000:.0f} ms more, {per:.3f} ms a fill")
    
  • cargo test -p horizon-client --bin horizon-client commands → test result: ok. 12 passed. There's no new unit test: the
    behaviour is pinned by the command_exec corpus.

  • python3 tools/parity.py command_exec fill_layer: not run here. This machine's prepared vanilla data predates
    the current research-lock.json, so the harnesses refuse it. CI's parity job runs them with run-parity.

For the merge

  • Depends on: nothing; independent of the rest of #5727's series.
  • Conflicts: none expected (cmd_fill in crates/horizon-client/src/game/commands.rs). #5735 adds a free
    function at the end of the same file, and both sides apply cleanly. Main was merged in on 2026-11-01.
  • Verify: parity with run-parity (command_exec, fill_layer).
  • Risk: low: the corpus pins command results. Rollback: git revert -m 1 <merge commit>.

Self-check

pr_ready (RUSTUP_TOOLCHAIN=1.99 tools/pr_ready.py --quick on DESKTOP-SNGRNA4-LINUX, against origin/main at 5edb339a7, 16 min 55 s)

Check Result
Scope ✅ 1 files, +20 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (30 s)
rustfmt ✅ (14 s)
clippy ✅ (2 min 10 s)
tests: horizon-client ✅ 1659 passed (13 min 59 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

CI's two clippy commands on Rust 1.99 (cargo clippy --workspace --all-targets -- -D warnings, cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings): both pass.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5686 **Author:** [@Stink-O](https://github.com/Stink-O) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `faster-fill` --- ### 📝 Commits (2) - [`4a7c664`](https://github.com/horizon-rust/horizon/commit/4a7c664eb8b76e2a2f3c6aa515acadabd0671b45) fill: skip blocks that are already the block, match the filter once per state - [`047b17f`](https://github.com/horizon-rust/horizon/commit/047b17f57b1a233d282bb87c27effd08309ee62a) Merge main into #5686 ### 📊 Changes **1 file changed** (+20 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands.rs` (+20 -3) </details> ### 📄 Description > 🤖 Opened by Stink-O's AI agent (Claude Code, Claude Opus 5.5), not by Stink-O personally. ## What and why Fixes #5684. Found while porting [Orbital Laser](https://github.com/Stink-O/orbital-laser) to native hooks (tracking: #5727), whose craters fill big regions; any large `/fill` gets cheaper. `cmd_fill` visits up to 32,768 blocks, usually of a handful of states. Two changes, with the same results: - The `replace <filter>` predicate is matched once per block state for the whole fill. Today a tag filter does a registry lookup and a tag-set lookup per block. - In the plain modes (not `destroy`, `hollow` or `outline`), a block that's already the fill's state is skipped before the filter. `place_state` returned `false` for it anyway, so it was never counted. Counts, feedback, `keep`, `strict`, block entities and `commands.fill.failed` are unchanged. ## Kind - [x] perf ## Vanilla reference `FillCommand.fillBlocks` / `BlockInput.place`: a state equal to the current one is no change, so it isn't counted. Harnesses: `command_exec` (its corpus, `tools/command_exec_corpus.py`, runs `/fill` in every mode, with and without `replace`) and `fill_layer`. ## Other projects' code None from other projects. Ported from the author's own fork of Horizon (Stink-O/horizon, MIT): [242b45037](https://github.com/Stink-O/horizon/commit/242b45037). ## How it was tested - **Measured** through Horizon's own headless command runner (`HORIZON_COMMAND_SCRIPT`, as `tools/test_command_exec_parity.py` uses it), fast profile, with the same world (seed 1, radius 4) on main (5edb339a7) and on this branch. The script times a run with 1 fill and a run with 1,001, three of each, and takes the fastest. The difference over 1,000 is one fill. Each fill is a 32×32×32 box of stone 20 blocks over the player: | Case | main | this PR | |---|---|---| | `fill ~ ~20 ~ ~31 ~51 ~31 stone replace #minecraft:logs` over stone (the filter matches nothing) | 3.26 ms | 0.51 ms | | `fill ~ ~20 ~ ~31 ~51 ~31 stone` over stone (every block already stone) | 0.53 ms | 0.08 ms | The script is ~50 lines of Python (below). Run it from a checkout with `.local` prepared: `python3 fill_bench.py target/fast/horizon-client 1000`. <details><summary>fill_bench.py</summary> ```python #!/usr/bin/env python3 """Time /fill on a Horizon checkout through its headless command runner (HORIZON_COMMAND_SCRIPT, as tools/test_command_exec_parity.py runs commands): the same world twice, once with 1 fill and once with 1 + N, and the difference over N is one fill's cost. Run from a Horizon checkout with .local prepared: python3 fill_bench.py BINARY [N] Cases (each a 32x32x32 box 20 blocks over the player, first made stone): replace: `fill ... stone replace #minecraft:logs` over stone (the tag filter matches nothing; the fill fails) plain: `fill ... stone` over stone (every block already the fill's) """ import json import subprocess import sys import tempfile import time from pathlib import Path sys.path.insert(0, str(Path.cwd() / "tools")) import lab # noqa: E402 BINARY = Path(sys.argv[1]).resolve() N = int(sys.argv[2]) if len(sys.argv) > 2 else 1000 BOX = "~ ~20 ~ ~31 ~51 ~31" CASES = {"replace": f"fill {BOX} stone replace #minecraft:logs", "plain": f"fill {BOX} stone"} def run(commands): with tempfile.TemporaryDirectory() as d: d = Path(d) script = [{"op": "settle"}, {"op": "cmd", "cmd": f"fill {BOX} stone", "record": False}] script += [{"op": "cmd", "cmd": c, "record": False} for c in commands] (d / "script.jsonl").write_text("".join(json.dumps(op) + "\n" for op in script)) env = lab.game_env(HORIZON_SERVER_THREAD=1, HORIZON_PLAYER_NAME="Player", HORIZON_COMMAND_SCRIPT=d / "script.jsonl", HORIZON_COMMAND_OUTPUT=d / "out.jsonl", HORIZON_API_DISCOVERY="http://127.0.0.1:9/") start = time.perf_counter() subprocess.run([BINARY, "--resources", lab.RESOURCES, "--world", "bench", "--seed", "1", "--radius", "4"], cwd=d, env=env, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return time.perf_counter() - start for name, command in CASES.items(): # Alternate short and long runs so drift hits both; keep the fastest of each. short, long = [], [] for _ in range(3): short.append(run([command])) long.append(run([command] * (N + 1))) per = (min(long) - min(short)) / N * 1000 print(f"{name}: {N} fills took {(min(long) - min(short)) * 1000:.0f} ms more, {per:.3f} ms a fill") ``` </details> - `cargo test -p horizon-client --bin horizon-client commands` → `test result: ok. 12 passed`. There's no new unit test: the behaviour is pinned by the `command_exec` corpus. - `python3 tools/parity.py command_exec fill_layer`: not run here. This machine's prepared vanilla data predates the current `research-lock.json`, so the harnesses refuse it. CI's `parity` job runs them with `run-parity`. ## For the merge - **Depends on:** nothing; independent of the rest of #5727's series. - **Conflicts:** none expected (`cmd_fill` in `crates/horizon-client/src/game/commands.rs`). #5735 adds a free function at the end of the same file, and both sides apply cleanly. Main was merged in on 2026-11-01. - **Verify:** `parity` with `run-parity` (`command_exec`, `fill_layer`). - **Risk:** low: the corpus pins command results. **Rollback:** `git revert -m 1 <merge commit>`. ## Self-check **pr_ready** (`RUSTUP_TOOLCHAIN=1.99 tools/pr_ready.py --quick` on DESKTOP-SNGRNA4-LINUX, against origin/main at 5edb339a7, 16 min 55 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +20 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (30 s) | | rustfmt | ✅ (14 s) | | clippy | ✅ (2 min 10 s) | | tests: horizon-client | ✅ 1659 passed (13 min 59 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | CI's two clippy commands on Rust 1.99 (`cargo clippy --workspace --all-targets -- -D warnings`, `cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings`): both pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:20:33 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6435
No description provided.