[PR #7719] Dedicated server: cut tick costs for spread-out players #7783

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7719
Author: @rdbtCVS
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: perf/spread-server-tick


📝 Commits (1)

  • 889f87b Dedicated server: cut tick costs for spread-out players

📊 Changes

7 files changed (+644 additions, -59 deletions)

View changed files

📝 crates/horizon-client-render/src/streaming.rs (+185 -11)
📝 crates/horizon-client/src/game/creatures.rs (+4 -7)
📝 crates/horizon-client/src/game/minecarts.rs (+87 -8)
📝 crates/horizon-client/src/game/natural_spawning.rs (+177 -5)
📝 crates/horizon-client/src/mobs/spawn_selection.rs (+106 -19)
📝 crates/horizon-protocol/src/connection.rs (+4 -0)
📝 crates/horizon-world/src/worldgen/generator_structures.rs (+81 -9)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally.

Closes #7713.

On a dedicated server whose players are spread out, much of each tick went to work that grows with players², carts², or the number of loaded chunks. This PR removes those costs. Behaviour does not change: every lookup returns the same results in the same order as the scan it replaces, nearest-player ties still go to the lowest index, and no random draws move.

Changes

# Where What
1 generator_structures.rs The structure start cache keeps two generations per shard (new and old, with hits promoted from old). Before, a full shard was cleared outright, and spread-out players overran its 65 536 chunks, so villages and outposts were assembled again on the tick thread.
2 streaming.rs Ranges::distance gets the nearest player area from ExtraCover's 64-chunk buckets with a bounded ring search, instead of scanning every player for every wanted column.
3 streaming.rs ExtraCover still answers when players are too far apart for its dense grid (more than about 16 000 blocks): the buckets take over, where before it fell back to scans.
4 minecarts.rs Cart lookups by id start from a hint (the next index), so tick_carts stops being carts².
5 minecarts.rs Cart-against-cart pushes only test carts in nearby chunk cells (CartCells).
6 minecarts.rs Mob and player pushes against carts use the same cells.
7 minecarts.rs push_from_cart skips carts more than 2 blocks away before it builds any box.
8 minecarts.rs cart_entity_collisions only builds boxes for entities within reach of the cart. Before, it built every mob's box for every cart.
9 natural_spawning.rs spawning_chunks finds the players near each chunk through 8-chunk cells (PlayerCells), not a scan of every player.
10 spawn_selection.rs SpawnState::players_near uses the same cells.
11 natural_spawning.rs, creatures.rs Each mob's nearest_player comes from a 64-block grid (NearestPlayers). With 8 or fewer players it scans as before.
12 connection.rs A read cut short by a signal (Interrupted) is retried. Before, it disconnected the player; attaching a profiler kicked everyone.

Measured

The run used horizon-client --dedicated (fast profile, 12 cores) with 120 horizon-bots explore bots on a grid 1 200 blocks apart, view and simulation distance 10, survival. Tick-thread time was sampled from stacks.

Before After
MSPT ~137–184 ms ~104–134 ms
p99 tick ~350–420 ms ~170–225 ms
Natural spawning, share of tick-thread samples 42.6 % 6.5 %
Jigsaw start rebuilds on the tick thread ~30 % of samples none seen

Tests

New unit tests compare each new lookup with the scan it replaces on random inputs:

  • start_cache_keeps_the_starts_still_asked_for
  • the_buckets_answer_as_the_scan
  • player_cells_find_what_a_scan_finds
  • nearest_players_find_what_a_scan_finds

Parity, run locally with tools/parity.py:

PASS server_entities, spawn_rules, natural_spawn, structure_layout, structure_start_nbt,
     decoration_region, dedicated_server, world_spawn#1..4
11 passed, 0 failed in 10.4 min.

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at 0f0fa62dc, 12 min 53 s)

Check Result
Scope ⚠️ 7 files, +644 −59; 703 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (38 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 28 s)
tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-protocol, horizon-world ❌ 3764 passed, 6 failed (10 min 5 s)
doc tests ✅ 0 passed (6 s)
content root tests ➖ content root untouched
mod API up to date ✅ (18 s)
Parity ➖ 370 affected, to run in CI (--quick)

Notes on the two flagged rows:

  • Failed tests. The 6 failures are the horizon-world level::tests::*piston* tests. They fail the same way on an unmodified origin/main worktree on this machine, which points to the local prepared data rather than this change.
  • Size. The PR is over 500 lines because each change ships with its test against a scan. Each numbered change is self-contained, so I can split it into per-area PRs (structures, streaming, minecarts, spawning, protocol) if you prefer.

🤖 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/7719 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/spread-server-tick` --- ### 📝 Commits (1) - [`889f87b`](https://github.com/horizon-rust/horizon/commit/889f87be50523ea981d0e0eb4d1a98f24ce1eb4f) Dedicated server: cut tick costs for spread-out players ### 📊 Changes **7 files changed** (+644 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/streaming.rs` (+185 -11) 📝 `crates/horizon-client/src/game/creatures.rs` (+4 -7) 📝 `crates/horizon-client/src/game/minecarts.rs` (+87 -8) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+177 -5) 📝 `crates/horizon-client/src/mobs/spawn_selection.rs` (+106 -19) 📝 `crates/horizon-protocol/src/connection.rs` (+4 -0) 📝 `crates/horizon-world/src/worldgen/generator_structures.rs` (+81 -9) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. Closes #7713. On a dedicated server whose players are spread out, much of each tick went to work that grows with players², carts², or the number of loaded chunks. This PR removes those costs. Behaviour does not change: every lookup returns the same results in the same order as the scan it replaces, nearest-player ties still go to the lowest index, and no random draws move. ## Changes | # | Where | What | |---|---|---| | 1 | `generator_structures.rs` | The structure start cache keeps two generations per shard (`new` and `old`, with hits promoted from `old`). Before, a full shard was cleared outright, and spread-out players overran its 65 536 chunks, so villages and outposts were assembled again on the tick thread. | | 2 | `streaming.rs` | `Ranges::distance` gets the nearest player area from `ExtraCover`'s 64-chunk buckets with a bounded ring search, instead of scanning every player for every wanted column. | | 3 | `streaming.rs` | `ExtraCover` still answers when players are too far apart for its dense grid (more than about 16 000 blocks): the buckets take over, where before it fell back to scans. | | 4 | `minecarts.rs` | Cart lookups by id start from a hint (the next index), so `tick_carts` stops being carts². | | 5 | `minecarts.rs` | Cart-against-cart pushes only test carts in nearby chunk cells (`CartCells`). | | 6 | `minecarts.rs` | Mob and player pushes against carts use the same cells. | | 7 | `minecarts.rs` | `push_from_cart` skips carts more than 2 blocks away before it builds any box. | | 8 | `minecarts.rs` | `cart_entity_collisions` only builds boxes for entities within reach of the cart. Before, it built every mob's box for every cart. | | 9 | `natural_spawning.rs` | `spawning_chunks` finds the players near each chunk through 8-chunk cells (`PlayerCells`), not a scan of every player. | | 10 | `spawn_selection.rs` | `SpawnState::players_near` uses the same cells. | | 11 | `natural_spawning.rs`, `creatures.rs` | Each mob's `nearest_player` comes from a 64-block grid (`NearestPlayers`). With 8 or fewer players it scans as before. | | 12 | `connection.rs` | A read cut short by a signal (`Interrupted`) is retried. Before, it disconnected the player; attaching a profiler kicked everyone. | ## Measured The run used `horizon-client --dedicated` (`fast` profile, 12 cores) with 120 `horizon-bots` explore bots on a grid 1 200 blocks apart, view and simulation distance 10, survival. Tick-thread time was sampled from stacks. | | Before | After | |---|---|---| | MSPT | ~137–184 ms | ~104–134 ms | | p99 tick | ~350–420 ms | ~170–225 ms | | Natural spawning, share of tick-thread samples | 42.6 % | 6.5 % | | Jigsaw start rebuilds on the tick thread | ~30 % of samples | none seen | ## Tests New unit tests compare each new lookup with the scan it replaces on random inputs: - `start_cache_keeps_the_starts_still_asked_for` - `the_buckets_answer_as_the_scan` - `player_cells_find_what_a_scan_finds` - `nearest_players_find_what_a_scan_finds` Parity, run locally with `tools/parity.py`: ``` PASS server_entities, spawn_rules, natural_spawn, structure_layout, structure_start_nbt, decoration_region, dedicated_server, world_spawn#1..4 11 passed, 0 failed in 10.4 min. ``` **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at 0f0fa62dc, 12 min 53 s) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +644 −59; 703 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (38 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 28 s) | | tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-protocol, horizon-world | ❌ 3764 passed, 6 failed (10 min 5 s) | | doc tests | ✅ 0 passed (6 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (18 s) | | Parity | ➖ 370 affected, to run in CI (--quick) | Notes on the two flagged rows: - **Failed tests.** The 6 failures are the `horizon-world` `level::tests::*piston*` tests. They fail the same way on an unmodified `origin/main` worktree on this machine, which points to the local prepared data rather than this change. - **Size.** The PR is over 500 lines because each change ships with its test against a scan. Each numbered change is self-contained, so I can split it into per-area PRs (structures, streaming, minecarts, spawning, protocol) if you prefer. 🤖 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>
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#7783
No description provided.