[PR #507] [MERGED] Collision scans: skip blocks with no shape, build the entity shape lazily (−6 % tick time) #2606

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

📋 Pull Request Information

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

Base: main ← Head: perf/collision-scan-empty


📝 Commits (1)

  • 55945ee Collision scans: skip blocks with no shape, build the entity shape lazily

📊 Changes

4 files changed (+49 additions, -17 deletions)

View changed files

📝 crates/horizon-client/src/collisions.rs (+13 -12)
📝 crates/horizon-world/examples/block_collision_scan_fixture.rs (+1 -0)
📝 crates/horizon-world/src/block_collision.rs (+9 -2)
📝 crates/horizon-world/src/block_collision_scan.rs (+26 -3)

📄 Description

What

BlockCollisionScan (vanilla's BlockCollisions) asked every cursor cell for its collision shape, moved the shape into place and intersected it with Shapes.create(box), even for air. Every Entity.collide pays for this, and with 600 mobs it was 20 % of the mob ticks. This PR:

  • adds CollisionBlock::empty_shape, set by the registry for states with no contextual rule and an empty cached shape (air, plants). The scan skips them without asking for a shape. Providers that build CollisionBlock themselves (the vanilla query-order fixture) leave it false, so their query logs don't change.
  • skips a shape whose bounds miss the box before moving it, since joinIsNotEmpty(AND) of the two is false anyway.
  • builds Shapes.create(box) the first time a shape isn't the unit cube. Finite bounds always produce one, so no error moves.
  • has SceneCollisions hand the scan the resident chunk itself, so a cell costs one section read instead of a chunk-map lookup.

Why

Collision resolution is the second largest cost of the mob ticks, after the supporting block (#495, #489).

Results

Fast profile, thread CPU time per tick, base/new × 3:

main this PR
Tick, mean 8.36 ms 7.85 ms (−6 %)
Mob ticks, mean 7.27 ms 6.74 ms

Same result: with every resolve and unobstructed run both ways side by side, 900,000 mob moves in the busy world gave bit-identical movement and 0 differences. block_collision_scan, registry_collision_scan, world_movement and world_collision_check are among the harnesses below.

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/507 **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/collision-scan-empty` --- ### 📝 Commits (1) - [`55945ee`](https://github.com/horizon-rust/horizon/commit/55945ee97524cb8a6fbfb5d1873a7d86b773f846) Collision scans: skip blocks with no shape, build the entity shape lazily ### 📊 Changes **4 files changed** (+49 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/collisions.rs` (+13 -12) 📝 `crates/horizon-world/examples/block_collision_scan_fixture.rs` (+1 -0) 📝 `crates/horizon-world/src/block_collision.rs` (+9 -2) 📝 `crates/horizon-world/src/block_collision_scan.rs` (+26 -3) </details> ### 📄 Description ## What `BlockCollisionScan` (vanilla's `BlockCollisions`) asked every cursor cell for its collision shape, moved the shape into place and intersected it with `Shapes.create(box)`, even for air. Every `Entity.collide` pays for this, and with 600 mobs it was 20 % of the mob ticks. This PR: - adds `CollisionBlock::empty_shape`, set by the registry for states with no contextual rule and an empty cached shape (air, plants). The scan skips them without asking for a shape. Providers that build `CollisionBlock` themselves (the vanilla query-order fixture) leave it false, so their query logs don't change. - skips a shape whose bounds miss the box before moving it, since `joinIsNotEmpty(AND)` of the two is false anyway. - builds `Shapes.create(box)` the first time a shape isn't the unit cube. Finite bounds always produce one, so no error moves. - has `SceneCollisions` hand the scan the resident chunk itself, so a cell costs one section read instead of a chunk-map lookup. ## Why Collision resolution is the second largest cost of the mob ticks, after the supporting block (#495, #489). ## Results Fast profile, thread CPU time per tick, base/new × 3: | | `main` | this PR | | --- | --- | --- | | Tick, mean | 8.36 ms | **7.85 ms** (−6 %) | | Mob ticks, mean | 7.27 ms | 6.74 ms | Same result: with every `resolve` and `unobstructed` run both ways side by side, 900,000 mob moves in the busy world gave bit-identical movement and 0 differences. `block_collision_scan`, `registry_collision_scan`, `world_movement` and `world_collision_check` are among the harnesses below. ### 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: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#2606
No description provided.