[PR #506] [MERGED] Mobs: shape only the cells that can support them (−11 % tick time) #2608

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

📋 Pull Request Information

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

Base: main ← Head: perf/supporting-block-cells


📝 Commits (1)

  • 54acb70 Mobs: shape only the cells that can support them

📊 Changes

1 file changed (+26 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/mobs/living.rs (+26 -2)

📄 Description

What

Entity.checkSupportingBlock runs Level.findSupportingBlock after every move of a mob on the ground (twice when it falls back to where the mob came from). Horizon looked up and built the collision shape of every cell of the cursor, 27 to 48 per call, and it was the largest single cost of the mob ticks: 21 % of them with 600 mobs.

Vanilla's BlockCollisions cursor skips the cells that can't touch the box, and this PR does the same. A block whose shape stays inside its own cell (not hasLargeCollisionShape, not a moving piston) can only meet the area when its cell does. So only those cells are shaped, plus large shapes such as fences. Picking the nearest block (ties to the greatest position) is a total order, so visiting column by column finds the same block, and the chunk is now looked up once per column instead of once per cell.

Why

Mob AI was 31 % of the main thread (FEATURES row E). #495 (10.7 ms integrated-server ticks) and #489 (freeze after load) both come from tick cost.

Results

Fast profile (release optimisations without LTO), thread CPU time per tick, base/new × 3:

main this PR
Tick, mean 8.36 ms 7.43 ms (−11 %)
Tick, p95 11.9 ms 11.3 ms
Mob ticks, mean 7.27 ms 6.30 ms

(Single-PR p99s are within run-to-run noise; the combined table below moves them clearly.)

Same result: with the old and new functions both run on every call and compared, 600,000 calls in the busy world (mobs on grass, paths, farmland, slabs and fences) gave 0 differences.

All four server-tick PRs together (release build)

This PR is one of four independent server-tick PRs (supporting block, collision scan, push grid, POI table). Built together with the release profile (thin LTO), base/new × 3:

Release, same world and settings main the four PRs
Tick CPU time, mean 7.40 ms 4.45 ms (−40 %)
Tick CPU time, p95 / p99 / max 11.8 / 20.6 / 35.5 ms 8.2 / 10.2 / 13.2 ms
Mob ticks (tick_mobs), mean 6.35 ms 3.46 ms
First 200 ticks after the world opens (CPU, #489) 1,431 ms 1,056 ms (−26 %)
Frame CPU time, mean (wall clock) 4.95 ms 1.79 ms
Average FPS / 1 % low (median of 3) 175 / 11 484 / 18
GPU time per frame not measured (offscreen) no rendering change

FPS and 1 % lows are from a machine at load ~40: compare the two columns, not the absolute values.

How it was measured

  • Machine: Mac mini M4 Pro (14 cores, Metal), shared with other agents' builds and harnesses (load average 35–40), so wall-clock frame times swing run to run. The primary figure is the integrated server's tick time in thread CPU time: a local, uncommitted patch times the existing spans with CLOCK_THREAD_CPUTIME_ID, so time spent descheduled by other processes doesn't count.
  • World: seed 1234, creative, the village of the village benchmark scene (-960, 66, 176), night (time set 18000, advance_time false). Next to it, a fenced pen with 400 summoned mobs (80 villagers, 80 cows, 80 sheep, 60 zombies, 60 chickens, 40 pigs). About 600 mobs in all. The world was saved once and restored before every run. Render distance 12, FPS uncapped, VSync off, offscreen 1280×720.
  • Run: load, 300 ticks of warm-up, then bench 40 (about 800 ticks). Builds are interleaved base/new × 3, and the table gives the mean of the three runs' averages (percentiles: median of the three).
  • Identical behaviour: checked in game by running the old and the new code side by side on every call over the same world (details above), and by the parity harnesses.

Self-check

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean, on one commit with the four server-tick PRs merged (and -p horizon-client -p horizon-world on each branch).
  • cargo test -p horizon-client --lib: 752 passed, 0 failed (four PRs merged). cargo test -p horizon-world: 154 passed.
  • Local parity, tools/parity.py --changed origin/main on the merged commit (4 at a time on a loaded Mac mini): 287 harnesses affected; 267 ran (the other 20 had already passed with the same inputs): 267 passed, 0 failed (116 min).

Nothing 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/506 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/supporting-block-cells` --- ### 📝 Commits (1) - [`54acb70`](https://github.com/horizon-rust/horizon/commit/54acb709e403423f4a84bba8022f31e3d2f6d230) Mobs: shape only the cells that can support them ### 📊 Changes **1 file changed** (+26 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/living.rs` (+26 -2) </details> ### 📄 Description ## What `Entity.checkSupportingBlock` runs `Level.findSupportingBlock` after every move of a mob on the ground (twice when it falls back to where the mob came from). Horizon looked up and built the collision shape of **every** cell of the cursor, 27 to 48 per call, and it was the largest single cost of the mob ticks: 21 % of them with 600 mobs. Vanilla's `BlockCollisions` cursor skips the cells that can't touch the box, and this PR does the same. A block whose shape stays inside its own cell (not `hasLargeCollisionShape`, not a moving piston) can only meet the area when its cell does. So only those cells are shaped, plus large shapes such as fences. Picking the nearest block (ties to the greatest position) is a total order, so visiting column by column finds the same block, and the chunk is now looked up once per column instead of once per cell. ## Why Mob AI was 31 % of the main thread (FEATURES row E). #495 (10.7 ms integrated-server ticks) and #489 (freeze after load) both come from tick cost. ## Results Fast profile (release optimisations without LTO), thread CPU time per tick, base/new × 3: | | `main` | this PR | | --- | --- | --- | | Tick, mean | 8.36 ms | **7.43 ms** (−11 %) | | Tick, p95 | 11.9 ms | 11.3 ms | | Mob ticks, mean | 7.27 ms | 6.30 ms | (Single-PR p99s are within run-to-run noise; the combined table below moves them clearly.) Same result: with the old and new functions both run on every call and compared, 600,000 calls in the busy world (mobs on grass, paths, farmland, slabs and fences) gave 0 differences. ### All four server-tick PRs together (release build) This PR is one of four independent server-tick PRs (supporting block, collision scan, push grid, POI table). Built together with the release profile (thin LTO), base/new × 3: | Release, same world and settings | `main` | the four PRs | | --- | --- | --- | | Tick CPU time, mean | 7.40 ms | **4.45 ms** (−40 %) | | Tick CPU time, p95 / p99 / max | 11.8 / 20.6 / 35.5 ms | **8.2 / 10.2 / 13.2 ms** | | Mob ticks (`tick_mobs`), mean | 6.35 ms | **3.46 ms** | | First 200 ticks after the world opens (CPU, #489) | 1,431 ms | **1,056 ms** (−26 %) | | Frame CPU time, mean (wall clock) | 4.95 ms | 1.79 ms | | Average FPS / 1 % low (median of 3) | 175 / 11 | 484 / 18 | | GPU time per frame | not measured (offscreen) | no rendering change | FPS and 1 % lows are from a machine at load ~40: compare the two columns, not the absolute values. ### How it was measured - **Machine:** Mac mini M4 Pro (14 cores, Metal), shared with other agents' builds and harnesses (load average 35–40), so wall-clock frame times swing run to run. The primary figure is the integrated server's **tick time in thread CPU time**: a local, uncommitted patch times the existing `spans` with `CLOCK_THREAD_CPUTIME_ID`, so time spent descheduled by other processes doesn't count. - **World:** seed 1234, creative, the village of the `village` benchmark scene (-960, 66, 176), night (`time set 18000`, `advance_time false`). Next to it, a fenced pen with 400 summoned mobs (80 villagers, 80 cows, 80 sheep, 60 zombies, 60 chickens, 40 pigs). About 600 mobs in all. The world was saved once and restored before every run. Render distance 12, FPS uncapped, VSync off, offscreen 1280×720. - **Run:** load, 300 ticks of warm-up, then `bench 40` (about 800 ticks). Builds are interleaved base/new × 3, and the table gives the mean of the three runs' averages (percentiles: median of the three). - **Identical behaviour:** checked in game by running the old and the new code side by side on every call over the same world (details above), and by the parity harnesses. ### Self-check - `cargo fmt --all --check`: clean. - `cargo clippy --workspace --all-targets -- -D warnings`: clean, on one commit with the four server-tick PRs merged (and `-p horizon-client -p horizon-world` on each branch). - `cargo test -p horizon-client --lib`: 752 passed, 0 failed (four PRs merged). `cargo test -p horizon-world`: 154 passed. - Local parity, `tools/parity.py --changed origin/main` on the merged commit (4 at a time on a loaded Mac mini): **287 harnesses affected; 267 ran (the other 20 had already passed with the same inputs): 267 passed, 0 failed** (116 min). Nothing 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:57:35 +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#2608
No description provided.