[PR #5237] [MERGED] Natural spawning: placement before the spawn list, flat player lists for the local mob cap #6157

Closed
opened 2026-11-03 06:15:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/spawn-lookups


📝 Commits (1)

  • a129533 Natural spawning: fewer lookups per chunk and per attempt

📊 Changes

5 files changed (+75 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/game/perspective.rs (+1 -0)
📝 crates/horizon-client/src/mobs/data.rs (+28 -2)
📝 crates/horizon-client/src/mobs/render.rs (+4 -0)
📝 crates/horizon-client/src/mobs/spawn_rules.rs (+1 -2)
📝 crates/horizon-client/src/mobs/spawn_selection.rs (+41 -34)

📄 Description

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

Roadmap server-tick (dedicated server at 20 TPS with 50–100 players). Natural spawning is the second-biggest part of the mobs' tick: about 20 ms a tick with 60 players.

What

  • Placement first. valid_position_for_type now checks the species' placement (isSpawnPositionOk: a few block reads) before it looks up the spawn list again (canSpawnMobAt: structures, biome). Both only read the level and draw no random number, so their order cannot change the answer, and most positions fail the placement. The placement of each species is now computed once and kept in MobData (species_placement), not built from a formatted id on every attempt.
  • Players near a chunk. LocalMobCapCalculator's per-chunk player lists live in one flat Vec (one range per chunk asked about), not a Vec per chunk. The players' mob counts are a Vec indexed by player, not a hash map. A player with nothing counted yet still passes canSpawn: zero is under every spawning category's cap.

The random draws, the order of the chunks and of the attempts, and every position tried are unchanged.

Numbers

playhorizon, --profile fast, CPUs 0-3 exclusive, 60 server bots (horizon-bots), seed 12345, view/sim distance 10, warm-up 120 s, 90 s window. A/B alternated with the base, 3 rounds for this PR and 4 for the base (one round was cut off by a restart):

MSPT avg per round median p99 (median) spawn_natural ms/tick (median)
main + spans 120.5 / 116.2 / 113.3 / 109.3 114.8 151.5 19.7
this PR + spans 114.4 / 103.4 / 109.6 109.6 (−4.5 %) 145.7 16.2 (−18 %)

The spans (spawn_natural, tick_creature_entities) come from a separate branch used only for the measurement. Whole-tick MSPT swings by ±5 % between rounds on this machine; the spawn_natural span moves the same way in every round.

Checks

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 27cb8f96b, 8 min 51 s)

Check Result
Scope ✅ 5 files, +75 −38
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (2 min 12 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 2 s)
tests: horizon-client ❌ 1332 passed, 1 failed (4 min 52 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 56 affected, to run in CI (--quick): arrow, block_removal, command_exec, composter, container_title, crafter, cursor_death, dedicated_server, dispenser, entity_components, entity_death_loot, entity_model and 44 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The one failure is lan_bot::guests_see_each_other_and_the_world_entities. Its set_read_timeout hit EINVAL on a socket the server had already closed, on a loaded Mac. Rerun three times on this branch: cargo test -p horizon-client --test lan_bot → 12 passed each time. The branch is rebased on current main (cargo check --bin horizon-client --tests clean). The affected parity harnesses (natural_spawn, spawn_rules, finalize_spawn, dedicated_server, server_entities) run in CI.

🤖 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/5237 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/spawn-lookups` --- ### 📝 Commits (1) - [`a129533`](https://github.com/horizon-rust/horizon/commit/a12953365171145ab66b22ab1727b7aec574dded) Natural spawning: fewer lookups per chunk and per attempt ### 📊 Changes **5 files changed** (+75 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/perspective.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/data.rs` (+28 -2) 📝 `crates/horizon-client/src/mobs/render.rs` (+4 -0) 📝 `crates/horizon-client/src/mobs/spawn_rules.rs` (+1 -2) 📝 `crates/horizon-client/src/mobs/spawn_selection.rs` (+41 -34) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Roadmap `server-tick` (dedicated server at 20 TPS with 50–100 players). Natural spawning is the second-biggest part of the mobs' tick: about 20 ms a tick with 60 players. ## What - **Placement first.** `valid_position_for_type` now checks the species' placement (`isSpawnPositionOk`: a few block reads) before it looks up the spawn list again (`canSpawnMobAt`: structures, biome). Both only read the level and draw no random number, so their order cannot change the answer, and most positions fail the placement. The placement of each species is now computed once and kept in `MobData` (`species_placement`), not built from a formatted id on every attempt. - **Players near a chunk.** `LocalMobCapCalculator`'s per-chunk player lists live in one flat `Vec` (one range per chunk asked about), not a `Vec` per chunk. The players' mob counts are a `Vec` indexed by player, not a hash map. A player with nothing counted yet still passes `canSpawn`: zero is under every spawning category's cap. The random draws, the order of the chunks and of the attempts, and every position tried are unchanged. ## Numbers playhorizon, `--profile fast`, CPUs 0-3 exclusive, 60 `server` bots (horizon-bots), seed 12345, view/sim distance 10, warm-up 120 s, 90 s window. A/B alternated with the base, 3 rounds for this PR and 4 for the base (one round was cut off by a restart): | | MSPT avg per round | median | p99 (median) | `spawn_natural` ms/tick (median) | |---|---|---|---|---| | main + spans | 120.5 / 116.2 / 113.3 / 109.3 | **114.8** | 151.5 | 19.7 | | this PR + spans | 114.4 / 103.4 / 109.6 | **109.6 (−4.5 %)** | 145.7 | **16.2 (−18 %)** | The spans (`spawn_natural`, `tick_creature_entities`) come from a separate branch used only for the measurement. Whole-tick MSPT swings by ±5 % between rounds on this machine; the `spawn_natural` span moves the same way in every round. ## Checks **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 27cb8f96b, 8 min 51 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +75 −38 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (2 min 12 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 2 s) | | tests: horizon-client | ❌ 1332 passed, 1 failed (4 min 52 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 56 affected, to run in CI (--quick): arrow, block_removal, command_exec, composter, container_title, crafter, cursor_death, dedicated_server, dispenser, entity_components, entity_death_loot, entity_model and 44 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The one failure is `lan_bot::guests_see_each_other_and_the_world_entities`. Its `set_read_timeout` hit `EINVAL` on a socket the server had already closed, on a loaded Mac. Rerun three times on this branch: `cargo test -p horizon-client --test lan_bot` → 12 passed each time. The branch is rebased on current main (`cargo check --bin horizon-client --tests` clean). The affected parity harnesses (`natural_spawn`, `spawn_rules`, `finalize_spawn`, `dedicated_server`, `server_entities`) run in CI. 🤖 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 06:15:06 +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#6157
No description provided.