[PR #738] [MERGED] Hoppers: look up the block only under five-slot containers #2770

Closed
opened 2026-11-02 15:58:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/738
Author: @ludovic111
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/17/2026
Merged by: @ludovic111

Base: main ← Head: perf/hopper-scan-five-slots


📝 Commits (1)

  • 2f82bec Hoppers: look up the block only under five-slot containers

📊 Changes

2 files changed (+12 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/containers.rs (+5 -2)
📝 crates/horizon-client/src/game/machines.rs (+7 -5)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What: to find the hoppers, tick_hoppers read the block under every plain container block entity each tick (chests, barrels, shulker boxes, dispensers, droppers, hoppers). A hopper's block entity is the only plain container with five slots: BlockEntity::for_block makes it, every path that creates a hopper's block entity goes through for_block, and BlockEntity::id already names a five-slot container the hopper when saving. So only five-slot containers have their block looked up now. A position still needs a hopper block to tick, as before (BlockEntityType.isValid). The five is one constant, containers::HOPPER_SLOTS, used in all three places.

The ticked set is unchanged with one exception: a stale 27-slot chest left under a hopper block, if one could exist, would no longer tick as a hopper. Vanilla doesn't tick it either, since a ChestBlockEntity has no hopper ticker.

Measured (dedicated server, 50 walking bots, seed 12345, view distance 10, Mac mini M4 Pro). tick_hoppers on the server thread, from the probe; base and this PR ran at the same time:

per tick base r1 this PR r1 base r2 this PR r2
median 57 µs 37 µs 60 µs 36 µs
25th percentile 52 µs 34 µs 55 µs 34 µs

The hopper scan's share of the server thread (sample): 5.7 % and 3.2 % on base, 1.2 % and 1.5 % with this PR. The saving is small at spawn: about 22 µs a tick, about 40 % of the scan. It grows with the number of containers in loaded chunks (villages, bases full of chests). The scan still walks the whole block entity map.

How it was measured

  • Mac mini (M4 Pro, 14 threads, 64 GB), shared with other agents' builds and parity runs: ~/fleet/load showed the CPU 72 to 92 % busy with a load average of 56 to 170 through the runs.
  • tools/server_bench.py --servers horizon --behaviour walk --bots 50 --warmup 30 --seconds 45 --gamerule locator_bar=false: seed 12345, view and simulation distance 10, bots on the same machine, fast profile, base = main 7bbbf6e9. Every run sent the bots the same chunks (490 to 505 a second, none sent twice).
  • Paired runs: the base and the new build ran at the same time (two servers, 50 bots each), so both saw the same load; they swapped worktrees between rounds.
  • Probe: a local patch, not part of this PR, timed the step with Instant on the server thread and logged one line per event. The numbers cover the 900 ticks of the measured window. The steps are much shorter than a scheduler time slice, so their medians are close to CPU time even on a loaded machine.
  • Share of the server thread: macOS sample of the engine for 20 s inside the measured window of a separate run per build. It counts wall time, so time spent waiting for a core counts too.
  • MSPT (/tick query average) didn't separate the builds on this machine. The server thread used only about 3 ms of CPU a tick (ps -M); with load averages up to 170 on 14 threads, most of a tick's wall time went to waiting for a core, and that spread is larger than these changes.

Checks

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-client --lib: 823 passed, 0 failed, 11 ignored
  • Local parity (tools/parity.py --changed origin/main, one run on #737, #738, #739 and #748 stacked together, plus the chunk-occupancy commit on perf/chunk-occupied-columns): 87 passed, 0 failed (every harness that depends on the 9 changed files).

Nothing here needs Ludovic.

🤖 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/738 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/hopper-scan-five-slots` --- ### 📝 Commits (1) - [`2f82bec`](https://github.com/horizon-rust/horizon/commit/2f82becb9ce7478a8c1625501f2d1a98fc68b74d) Hoppers: look up the block only under five-slot containers ### 📊 Changes **2 files changed** (+12 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/containers.rs` (+5 -2) 📝 `crates/horizon-client/src/game/machines.rs` (+7 -5) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **What:** to find the hoppers, `tick_hoppers` read the block under every plain container block entity each tick (chests, barrels, shulker boxes, dispensers, droppers, hoppers). A hopper's block entity is the only plain container with five slots: `BlockEntity::for_block` makes it, every path that creates a hopper's block entity goes through `for_block`, and `BlockEntity::id` already names a five-slot container the hopper when saving. So only five-slot containers have their block looked up now. A position still needs a hopper block to tick, as before (`BlockEntityType.isValid`). The five is one constant, `containers::HOPPER_SLOTS`, used in all three places. The ticked set is unchanged with one exception: a stale 27-slot chest left under a hopper block, if one could exist, would no longer tick as a hopper. Vanilla doesn't tick it either, since a ChestBlockEntity has no hopper ticker. **Measured** (dedicated server, 50 walking bots, seed 12345, view distance 10, Mac mini M4 Pro). `tick_hoppers` on the server thread, from the probe; base and this PR ran at the same time: | per tick | base r1 | this PR r1 | base r2 | this PR r2 | |---|---:|---:|---:|---:| | median | 57 µs | 37 µs | 60 µs | 36 µs | | 25th percentile | 52 µs | 34 µs | 55 µs | 34 µs | The hopper scan's share of the server thread (`sample`): 5.7 % and 3.2 % on base, 1.2 % and 1.5 % with this PR. The saving is small at spawn: about 22 µs a tick, about 40 % of the scan. It grows with the number of containers in loaded chunks (villages, bases full of chests). The scan still walks the whole block entity map. **How it was measured** - Mac mini (M4 Pro, 14 threads, 64 GB), shared with other agents' builds and parity runs: `~/fleet/load` showed the CPU 72 to 92 % busy with a load average of 56 to 170 through the runs. - `tools/server_bench.py --servers horizon --behaviour walk --bots 50 --warmup 30 --seconds 45 --gamerule locator_bar=false`: seed 12345, view and simulation distance 10, bots on the same machine, `fast` profile, base = main 7bbbf6e9. Every run sent the bots the same chunks (490 to 505 a second, none sent twice). - **Paired runs:** the base and the new build ran at the same time (two servers, 50 bots each), so both saw the same load; they swapped worktrees between rounds. - **Probe:** a local patch, not part of this PR, timed the step with `Instant` on the server thread and logged one line per event. The numbers cover the 900 ticks of the measured window. The steps are much shorter than a scheduler time slice, so their medians are close to CPU time even on a loaded machine. - **Share of the server thread:** macOS `sample` of the engine for 20 s inside the measured window of a separate run per build. It counts wall time, so time spent waiting for a core counts too. - MSPT (`/tick query` average) didn't separate the builds on this machine. The server thread used only about 3 ms of CPU a tick (`ps -M`); with load averages up to 170 on 14 threads, most of a tick's wall time went to waiting for a core, and that spread is larger than these changes. **Checks** - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client --lib`: 823 passed, 0 failed, 11 ignored - Local parity (`tools/parity.py --changed origin/main`, one run on #737, #738, #739 and #748 stacked together, plus the chunk-occupancy commit on `perf/chunk-occupied-columns`): 87 passed, 0 failed (every harness that depends on the 9 changed files). Nothing here needs Ludovic. 🤖 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-02 15:58:54 +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#2770
No description provided.