[PR #1202] [MERGED] Mob tick: drop repeated scans in guest bindings, villagers, allays, piglins and sculk #3415

Closed
opened 2026-11-03 04:09:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: claude/upstream-mob-scans


📝 Commits (4)

  • 67ca65b Mob tick: drop gone mobs' guest bindings with a set, not a scan per binding
  • a893fa6 Villagers: count the others' POI tickets once per search
  • 863a309 Allays and piglins: hoist per-tick lookups out of the per-mob loop
  • cb0bbe7 Sculk: skip the loaded-chunk diff while no chunk came or went

📊 Changes

6 files changed (+59 additions, -17 deletions)

View changed files

📝 crates/horizon-client/src/game/allays.rs (+16 -6)
📝 crates/horizon-client/src/game/creatures.rs (+5 -1)
📝 crates/horizon-client/src/game/piglins.rs (+13 -1)
📝 crates/horizon-client/src/game/sculk.rs (+6 -1)
📝 crates/horizon-client/src/game/sculk_fixture.rs (+1 -0)
📝 crates/horizon-client/src/mobs/villager_brain.rs (+18 -8)

📄 Description

Requested by JR

What and why

Mob tick: drop gone mobs' guest bindings with a set, not a scan per binding

On a server every ticked mob is bound to its nearest player, and each tick
the bindings of mobs that are gone were dropped by scanning every mob for
each binding. Mob is 1.5 KB, so the scan misses the cache on every mob:
with 1000 loaded mobs that was 0.44 ms a tick, with 2000 1.86 ms; a set of
the live ids makes it 0.02 and 0.04 ms (stand-in structs of Mob's size).

Villagers: count the others' POI tickets once per search

pois_in_range (AcquirePoi and the job, bed and meeting point searches)
asked, for every candidate POI in range, how many tickets it had, and
each answer scanned every other mob for villagers holding it: POIs times
mobs per search. The others' tickets are now counted into a map at the
first candidate and read from it; this villager's own memories are
still checked per POI, as before.

Allays and piglins: hoist per-tick lookups out of the per-mob loop

tick_allays scanned every block entity of the level for each allay,
every tick, to find a playing jukebox within 10 blocks. The playing
jukeboxes are now collected once, at the first allay (no allay starts
or stops one).

piglin_pickups looked up the piglin_loved tag and hashed every item
entity's id once per piglin. Each item's flag is now computed once and
kept until an item is added (always pushed at the end under a new id)
or removed.

Sculk: skip the loaded-chunk diff while no chunk came or went

sculk_sync_index collected every loaded chunk key into a set and diffed
it against the known chunks every ten ticks, thousands of keys on a busy
server. It now remembers the chunk map's membership revision and skips
the diff while it is unchanged; a replaced chunk keeps its key and was
not rescanned before either.

Vanilla reference

Same results as before, following Allay (jukebox listening), PiglinAi's loved-item check (the piglin_loved tag), AcquirePoi with PoiRecord's free tickets, and SculkSpreader. Guest bindings and the sculk chunk index are Horizon-only. Harnesses: test_mob_ai_parity.py, test_sculk_parity.py.

Self-check

pr_ready (tools/pr_ready.py --base upstream/main on Mac, against upstream/main at fd0473605, 1 min 15 s)

Check Result
Scope ✅ 6 files, +59 −17
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (20 s)
tests: horizon-client ✅ 1080 passed (46 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (no vanilla data here): 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)

🤖 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/1202 **Author:** [@pirut](https://github.com/pirut) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `claude/upstream-mob-scans` --- ### 📝 Commits (4) - [`67ca65b`](https://github.com/horizon-rust/horizon/commit/67ca65bb3b003999c511a4bd729274acc0f6da38) Mob tick: drop gone mobs' guest bindings with a set, not a scan per binding - [`a893fa6`](https://github.com/horizon-rust/horizon/commit/a893fa6125eacaa13ea9db58d2c8d0e278bee1f3) Villagers: count the others' POI tickets once per search - [`863a309`](https://github.com/horizon-rust/horizon/commit/863a3091612f065e9118fc94c709249fa14ada68) Allays and piglins: hoist per-tick lookups out of the per-mob loop - [`cb0bbe7`](https://github.com/horizon-rust/horizon/commit/cb0bbe7d19e0123e11915244f906791786dd244d) Sculk: skip the loaded-chunk diff while no chunk came or went ### 📊 Changes **6 files changed** (+59 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/allays.rs` (+16 -6) 📝 `crates/horizon-client/src/game/creatures.rs` (+5 -1) 📝 `crates/horizon-client/src/game/piglins.rs` (+13 -1) 📝 `crates/horizon-client/src/game/sculk.rs` (+6 -1) 📝 `crates/horizon-client/src/game/sculk_fixture.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/villager_brain.rs` (+18 -8) </details> ### 📄 Description <!-- claude-projects-attribution: {"github_login":"pirut"} --> _Requested by **JR**_ ## What and why Mob tick: drop gone mobs' guest bindings with a set, not a scan per binding On a server every ticked mob is bound to its nearest player, and each tick the bindings of mobs that are gone were dropped by scanning every mob for each binding. Mob is 1.5 KB, so the scan misses the cache on every mob: with 1000 loaded mobs that was 0.44 ms a tick, with 2000 1.86 ms; a set of the live ids makes it 0.02 and 0.04 ms (stand-in structs of Mob's size). Villagers: count the others' POI tickets once per search pois_in_range (AcquirePoi and the job, bed and meeting point searches) asked, for every candidate POI in range, how many tickets it had, and each answer scanned every other mob for villagers holding it: POIs times mobs per search. The others' tickets are now counted into a map at the first candidate and read from it; this villager's own memories are still checked per POI, as before. Allays and piglins: hoist per-tick lookups out of the per-mob loop tick_allays scanned every block entity of the level for each allay, every tick, to find a playing jukebox within 10 blocks. The playing jukeboxes are now collected once, at the first allay (no allay starts or stops one). piglin_pickups looked up the piglin_loved tag and hashed every item entity's id once per piglin. Each item's flag is now computed once and kept until an item is added (always pushed at the end under a new id) or removed. Sculk: skip the loaded-chunk diff while no chunk came or went sculk_sync_index collected every loaded chunk key into a set and diffed it against the known chunks every ten ticks, thousands of keys on a busy server. It now remembers the chunk map's membership revision and skips the diff while it is unchanged; a replaced chunk keeps its key and was not rescanned before either. ## Vanilla reference Same results as before, following `Allay` (jukebox listening), `PiglinAi`'s loved-item check (the `piglin_loved` tag), `AcquirePoi` with `PoiRecord`'s free tickets, and `SculkSpreader`. Guest bindings and the sculk chunk index are Horizon-only. Harnesses: `test_mob_ai_parity.py`, `test_sculk_parity.py`. ## Self-check **pr_ready** (`tools/pr_ready.py --base upstream/main` on Mac, against upstream/main at fd0473605, 1 min 15 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +59 −17 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (20 s) | | tests: horizon-client | ✅ 1080 passed (46 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (no vanilla data here): 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) | 🤖 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 04:09:22 +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#3415
No description provided.