[PR #355] [MERGED] Natural spawning skips air sections when finding the surface #2516

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

📋 Pull Request Information

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

Base: main ← Head: perf/spawn-heightmap


📝 Commits (1)

  • 7f631bb Natural spawning skips sections of air when it finds the surface

📊 Changes

2 files changed (+61 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/chunk.rs (+50 -0)
📝 crates/horizon-client/src/game/natural_spawning.rs (+11 -4)

📄 Description

What

Natural spawning finds the surface (getHeight) without testing every block from the top of the world: sections holding only air are skipped whole.

Why

From profiling a typical session (card #23, item 4: flying over the village scene at RD16 on the Mac mini, macOS sample), the main thread spent its time in:

main thread share of samples
Game::tick_mobs 55 %
… of which mob entity ticks (AI, movement, collisions, villager POI search) 31 %
… of which the rest of tick_creatures, mostly natural spawning ~25 %
Game::render 13 %
Game::update_world (streaming, uploads) 6 %

Most of that 25 % was GameLevel::heightmap: for every spawnable chunk, every tick, it tested every block from y 319 down (with a block-tag lookup for each) until it reached the surface. Vanilla reads a heightmap it keeps up to date.

How

Chunk::highest(skip, matches): scans down, passing over sections that hold only skip. GameLevel::heightmap passes air (which counts for no heightmap type: WORLD_SURFACE is "not air", the others need a fluid or #blocks_motion_in_heightmap*). An unloaded column still gives the bottom of the world, as reading air everywhere did. The heights are the same.

Measurements

Mac mini M4 Pro, RD16, PerfBench world (seed 1234), standing at the start of the village scene, sample of the main thread for 15 s; two games per build, interleaved. Share of main-thread samples in tick_mobs outside the mob entity ticks (spawning and the other per-tick passes):

main this PR
game 1 23 % 11 %
game 2 17 % 12 %

What is left of natural spawning is about 5 % of the main thread. Other sessions kept the machine busy, so frame times weren't a usable signal; the sample shares are relative to the game's own main thread.

How tested

cargo fmt --all -- --check                                   OK
cargo clippy --workspace --all-targets -- -D warnings        OK
cargo test -p horizon-client                                 all passed
  new: chunk::tests::highest_skips_only_sections_that_cannot_match (same answer as the full scan)
parity.py --changed origin/main                         80 passed, 0 failed (one run on the merge
                                                             of this PR with its three siblings: #270 relight
                                                             remesh, #224 proto saves, #271 frame cap, spawn
                                                             heightmap; includes section_mesh, light, natural_spawn,
                                                             spawn_rules, world_spawn, frame_limiter, game_loop)

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/355 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/spawn-heightmap` --- ### 📝 Commits (1) - [`7f631bb`](https://github.com/horizon-rust/horizon/commit/7f631bb36f495d486bfa695a05c87427a0522176) Natural spawning skips sections of air when it finds the surface ### 📊 Changes **2 files changed** (+61 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/chunk.rs` (+50 -0) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+11 -4) </details> ### 📄 Description ## What Natural spawning finds the surface (`getHeight`) without testing every block from the top of the world: sections holding only air are skipped whole. ## Why From profiling a typical session (card #23, item 4: flying over the village scene at RD16 on the Mac mini, macOS `sample`), the main thread spent its time in: | main thread | share of samples | |---|---| | `Game::tick_mobs` | 55 % | | … of which mob entity ticks (AI, movement, collisions, villager POI search) | 31 % | | … of which the rest of `tick_creatures`, mostly natural spawning | ~25 % | | `Game::render` | 13 % | | `Game::update_world` (streaming, uploads) | 6 % | Most of that 25 % was `GameLevel::heightmap`: for every spawnable chunk, every tick, it tested every block from y 319 down (with a block-tag lookup for each) until it reached the surface. Vanilla reads a heightmap it keeps up to date. ## How `Chunk::highest(skip, matches)`: scans down, passing over sections that hold only `skip`. `GameLevel::heightmap` passes air (which counts for no heightmap type: `WORLD_SURFACE` is "not air", the others need a fluid or `#blocks_motion_in_heightmap*`). An unloaded column still gives the bottom of the world, as reading air everywhere did. The heights are the same. ## Measurements Mac mini M4 Pro, RD16, PerfBench world (seed 1234), standing at the start of the village scene, `sample` of the main thread for 15 s; two games per build, interleaved. Share of main-thread samples in `tick_mobs` outside the mob entity ticks (spawning and the other per-tick passes): | | main | this PR | |---|---|---| | game 1 | 23 % | **11 %** | | game 2 | 17 % | **12 %** | What is left of natural spawning is about 5 % of the main thread. Other sessions kept the machine busy, so frame times weren't a usable signal; the sample shares are relative to the game's own main thread. ## How tested ``` cargo fmt --all -- --check OK cargo clippy --workspace --all-targets -- -D warnings OK cargo test -p horizon-client all passed new: chunk::tests::highest_skips_only_sections_that_cannot_match (same answer as the full scan) parity.py --changed origin/main 80 passed, 0 failed (one run on the merge of this PR with its three siblings: #270 relight remesh, #224 proto saves, #271 frame cap, spawn heightmap; includes section_mesh, light, natural_spawn, spawn_rules, world_spawn, frame_limiter, game_loop) ``` 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:56:51 +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#2516
No description provided.