[PR #952] [MERGED] tick_blocks: scan for the motion-blocking top from the world surface, not the build limit #2935

Closed
opened 2026-11-02 16:00:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/heightmap-scan-from-surface


📝 Commits (1)

  • e805e98 Scan for the motion-blocking top from the world surface, not the build limit

📊 Changes

3 files changed (+13 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+3 -0)
📝 crates/horizon-world/src/level/mod.rs (+6 -0)
📝 crates/horizon-world/src/level/weather.rs (+4 -2)

📄 Description

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

Part of the tick_blocks cost follow-up to #931 (#890).

The problem

Behaviours::motion_blocking_top (getHeightmapPos(MOTION_BLOCKING)) walked every column from y 319 down, with one block lookup per y. Two things call it:

  • every precipitation roll in tick_chunk_random (3 in 48 per ticking chunk per tick: freezing and snow), which runs even in clear weather;
  • every isRainingAt.

With the chunks of 10 players ticking, a sample of the dedicated server put most of tick_blocks' own time in these scans. Vanilla reads a stored heightmap instead.

What this changes

Only air lies above the WORLD_SURFACE heightmap, which each chunk already keeps (Chunk::world_surface, updated by Chunk::set as Heightmap.update does). Air neither blocks motion nor holds a fluid, so the scan starts at the world surface. The answer is the same, without the walk through the empty sky.

  • LevelAccess::world_surface(x, z) is new. Its default is max_y, so the fixtures and other levels scan the whole column as before. The game's GameLevel answers from the chunk's heightmap, with the same air test natural spawning uses.
  • motion_blocking_top scans from world_surface down.

The order of the ticks and the random draws are unchanged.

Proof

Check Result
cargo clippy -p horizon-world -p horizon-client --all-targets -D warnings clean
integration commit with #950 and #951 over a9bcaa6e: workspace clippy, cargo test -p horizon-client -p horizon-world clean, all ok
integration: parity.py --changed origin/main (every harness, since horizon-world changed) 301 passed, 0 failed (every harness)

Cost

These runs use a dedicated server with 10 walking bots and bench settings (view and simulation distance 10). The figures are HORIZON_SPIKES spans averaged over 1200 ticks, on the Mac mini while it was quiet, one run after the other:

Build tick_blocks ms/tick Mean tick ms P95 ms
before 1.98 8.41 (with natural spawning) 18.2
this branch 1.36 4.76 (without) 8.7

The before build had #950's natural spawning (2.6 ms of tick_mobs), so compare the tick_blocks column only: 31 % less.

On the ThinkPad, server_bench.py --bots 10,25 --behaviour walk doesn't show it in MSPT. Old main 25f2e239 measured 15.84 and 18.53 ms; this change on top of it measured 16.03 and 18.12 ms, within noise. There, tick_blocks is one of several systems at 2 to 3 ms each.

What's left in tick_blocks is the random ticks' block reads (PalettedContainer::get, a cache miss for each random position). Vanilla makes the same reads in the same order.

🤖 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/952 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/heightmap-scan-from-surface` --- ### 📝 Commits (1) - [`e805e98`](https://github.com/horizon-rust/horizon/commit/e805e9886c06d37685c27e3056717e425da4aa59) Scan for the motion-blocking top from the world surface, not the build limit ### 📊 Changes **3 files changed** (+13 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+3 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+6 -0) 📝 `crates/horizon-world/src/level/weather.rs` (+4 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the `tick_blocks` cost follow-up to #931 (#890). ## The problem `Behaviours::motion_blocking_top` (`getHeightmapPos(MOTION_BLOCKING)`) walked every column from y 319 down, with one block lookup per y. Two things call it: - every precipitation roll in `tick_chunk_random` (3 in 48 per ticking chunk per tick: freezing and snow), which runs even in clear weather; - every `isRainingAt`. With the chunks of 10 players ticking, a `sample` of the dedicated server put most of `tick_blocks`' own time in these scans. Vanilla reads a stored heightmap instead. ## What this changes Only air lies above the WORLD_SURFACE heightmap, which each chunk already keeps (`Chunk::world_surface`, updated by `Chunk::set` as `Heightmap.update` does). Air neither blocks motion nor holds a fluid, so the scan starts at the world surface. The answer is the same, without the walk through the empty sky. - `LevelAccess::world_surface(x, z)` is new. Its default is `max_y`, so the fixtures and other levels scan the whole column as before. The game's `GameLevel` answers from the chunk's heightmap, with the same air test natural spawning uses. - `motion_blocking_top` scans from `world_surface` down. The order of the ticks and the random draws are unchanged. ## Proof | Check | Result | | --- | --- | | `cargo clippy -p horizon-world -p horizon-client --all-targets -D warnings` | clean | | integration commit with #950 and #951 over `a9bcaa6e`: workspace clippy, `cargo test -p horizon-client -p horizon-world` | clean, all ok | | integration: `parity.py --changed origin/main` (every harness, since `horizon-world` changed) | 301 passed, 0 failed (every harness) | ## Cost These runs use a dedicated server with 10 walking bots and bench settings (view and simulation distance 10). The figures are `HORIZON_SPIKES` spans averaged over 1200 ticks, on the Mac mini while it was quiet, one run after the other: | Build | `tick_blocks` ms/tick | Mean tick ms | P95 ms | | --- | --- | --- | --- | | before | 1.98 | 8.41 (with natural spawning) | 18.2 | | this branch | 1.36 | 4.76 (without) | 8.7 | The before build had #950's natural spawning (2.6 ms of `tick_mobs`), so compare the `tick_blocks` column only: 31 % less. On the ThinkPad, `server_bench.py --bots 10,25 --behaviour walk` doesn't show it in MSPT. Old main `25f2e239` measured 15.84 and 18.53 ms; this change on top of it measured 16.03 and 18.12 ms, within noise. There, `tick_blocks` is one of several systems at 2 to 3 ms each. What's left in `tick_blocks` is the random ticks' block reads (`PalettedContainer::get`, a cache miss for each random position). Vanilla makes the same reads in the same order. 🤖 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 16:00:13 +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#2935
No description provided.