[PR #2033] [MERGED] Mob fluid and supporting-block scans skip sections that can't hold a match #3955

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

📋 Pull Request Information

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

Base: main ← Head: perf/mob-ai-tick


📝 Commits (1)

  • 053291e Mob scans skip sections that can't hold what they look for

📊 Changes

2 files changed (+106 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/mobs/living.rs (+43 -8)
📝 crates/horizon-client/src/world.rs (+63 -0)

📄 Description

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

Every tick, each mob's fluid state (MobWorld::fluids) and its supporting block (MobWorld::supporting_block) read every cell around its box. World::may_hold(lo, hi, matches) answers first from the palettes of the sections the box reaches:

  • fluids: if no fluid state is listed in those palettes, it returns no fluid without reading a cell.
  • supporting block: if no listed state reaches out of its cell (BlockCollisionRegistry::reaches_out: large collision shapes, moving pistons), it reads only the cells that meet the searched area, as BlockCollisions' cursor does. It is the same idea as #1977's outer-shell skip.

A global (unpaletted) section, a missing column (read as air) and heights outside the sections (state 0) always count as "may hold", so results are unchanged. No random draw is involved.

I tried the same gate on fire_contact (mobs, items, player) and dropped it. Its matcher compares block names, and for small boxes scanning the palette costs more than reading the 1-8 cells: fire_contact went from 1.13% to 1.50% of the samples.

Measured (ThinkPad i5-7200U, dedicated server, 10 walk bots, server_bench --behaviour walk --warmup 60 --seconds 120)

Sample shares of the tick thread, perf record -e cycles:u --call-graph lbr over 60 s, same command, ~82k samples each (main 7ecb43cc vs this branch):

function (inclusive) main this PR
MobWorld::supporting_block 2.00% 1.10%
MobWorld::fluids 1.51% 1.09%
Mob::do_move 8.80% 7.48%

That is −1.3% of the tick thread's cycles, about 0.27 Mcycles/tick of ~20. Whole-run totals can't resolve a change this small: instruction counts vary ~6% between runs of the same binary (spawns and walks differ). Alternated runs, perf stat on the tick thread:

run Mcycles/tick Minstr/tick MSPT clock
main #1 21.38 26.10 17.19 ~2.1 GHz
PR #1 19.82 25.55 17.94 ~2.1 GHz
main #2 19.77 24.63 17.01 ~1.7 GHz
PR #2 18.95 24.86 17.61 ~1.7 GHz

Vanilla 26.3, same command and machine: 42.0 Mcycles/tick, MSPT 16.14 at ~2.2 GHz. Its JIT and GC threads keep the shared clock high, while Horizon's tick thread runs at 0.9-1.7 GHz under powersave. So MSPT on this machine compares clock speeds more than code.

Checks

  • python3 tools/pr_ready.py on the first version of this branch (which also gated fire_contact): Parity pass for all harnesses parity.py --changed-files picks (78 shards, 57 min). The final version only removes the fire_contact gate.
  • tools/pr_ready.py --quick on the final head:

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at ee6dfd2b6, 11 min 25 s)

Check Result
Scope ✅ 2 files, +106 −8
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
rustfmt ✅ (11 s)
clippy ✅ (53 s)
tests: horizon-client ✅ 1295 passed (9 min 15 s)
doc tests ✅ 0 passed (4 s)
  • tools/lan_e2e.py --check mobs --check hazards, host in-frame and --server-thread: all pass.
  • New unit test world::tests::may_hold_reads_the_palettes_of_the_reached_sections.

No label: a speed-up players don't see.

🤖 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/2033 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/mob-ai-tick` --- ### 📝 Commits (1) - [`053291e`](https://github.com/horizon-rust/horizon/commit/053291e3392abf47c495bf6c8ea9dc0f1d37d64c) Mob scans skip sections that can't hold what they look for ### 📊 Changes **2 files changed** (+106 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/living.rs` (+43 -8) 📝 `crates/horizon-client/src/world.rs` (+63 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Every tick, each mob's fluid state (`MobWorld::fluids`) and its supporting block (`MobWorld::supporting_block`) read every cell around its box. `World::may_hold(lo, hi, matches)` answers first from the palettes of the sections the box reaches: - **fluids:** if no fluid state is listed in those palettes, it returns no fluid without reading a cell. - **supporting block:** if no listed state reaches out of its cell (`BlockCollisionRegistry::reaches_out`: large collision shapes, moving pistons), it reads only the cells that meet the searched area, as `BlockCollisions`' cursor does. It is the same idea as #1977's outer-shell skip. A global (unpaletted) section, a missing column (read as air) and heights outside the sections (state 0) always count as "may hold", so results are unchanged. No random draw is involved. I tried the same gate on `fire_contact` (mobs, items, player) and dropped it. Its matcher compares block names, and for small boxes scanning the palette costs more than reading the 1-8 cells: fire_contact went from 1.13% to 1.50% of the samples. ### Measured (ThinkPad i5-7200U, dedicated server, 10 walk bots, `server_bench --behaviour walk --warmup 60 --seconds 120`) Sample shares of the tick thread, `perf record -e cycles:u --call-graph lbr` over 60 s, same command, ~82k samples each (main 7ecb43cc vs this branch): | function (inclusive) | main | this PR | |---|---|---| | `MobWorld::supporting_block` | 2.00% | 1.10% | | `MobWorld::fluids` | 1.51% | 1.09% | | `Mob::do_move` | 8.80% | 7.48% | That is **−1.3% of the tick thread's cycles**, about 0.27 Mcycles/tick of ~20. Whole-run totals can't resolve a change this small: instruction counts vary ~6% between runs of the same binary (spawns and walks differ). Alternated runs, `perf stat` on the tick thread: | run | Mcycles/tick | Minstr/tick | MSPT | clock | |---|---|---|---|---| | main #1 | 21.38 | 26.10 | 17.19 | ~2.1 GHz | | PR #1 | 19.82 | 25.55 | 17.94 | ~2.1 GHz | | main #2 | 19.77 | 24.63 | 17.01 | ~1.7 GHz | | PR #2 | 18.95 | 24.86 | 17.61 | ~1.7 GHz | Vanilla 26.3, same command and machine: 42.0 Mcycles/tick, MSPT 16.14 at ~2.2 GHz. Its JIT and GC threads keep the shared clock high, while Horizon's tick thread runs at 0.9-1.7 GHz under `powersave`. So MSPT on this machine compares clock speeds more than code. ### Checks - `python3 tools/pr_ready.py` on the first version of this branch (which also gated `fire_contact`): Parity **pass** for all harnesses `parity.py --changed-files` picks (78 shards, 57 min). The final version only removes the fire_contact gate. - `tools/pr_ready.py --quick` on the final head: **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at ee6dfd2b6, 11 min 25 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +106 −8 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (53 s) | | tests: horizon-client | ✅ 1295 passed (9 min 15 s) | | doc tests | ✅ 0 passed (4 s) | - `tools/lan_e2e.py --check mobs --check hazards`, host in-frame and `--server-thread`: all pass. - New unit test `world::tests::may_hold_reads_the_palettes_of_the_reached_sections`. No label: a speed-up players don't see. 🤖 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:13:34 +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#3955
No description provided.