[PR #7836] Dedicated server: tile sparse chunk ticket maps #7852

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

📋 Pull Request Information

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

Base: main ← Head: t3/dedicated-server-100-player-optimisations


📝 Commits (1)

  • 9e114dc perf: tile sparse chunk ticket levels

📊 Changes

2 files changed (+264 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/ticket_levels.rs (+120 -8)
➕ tools/bench_ticket_levels.py (+144 -0)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Codex, gpt-6.1-sol), not by rdbtCVS personally.

What and why

With players far enough apart that the ticket bounding box no longer fits the dense grid, crossing a chunk boundary rebuilds a hash entry for every chunk in every player's ticket area. Store those levels in sparse 16×16 tiles instead: hash once per intersecting tile during construction, then lower the same loading and simulation levels in contiguous cells. Queries still hash once and index the cell. The dense-grid path and unchanged-source cache remain in place.

Fixes #7814. Independent of #7719: no spawning, streaming-range, structure-cache or minecart changes are duplicated.

Benchmark

taskset -c 11 python3 tools/bench_ticket_levels.py --base f1d6576b3 --rounds 100 --output tickets.json

Linux x86_64, 6 physical / 12 logical CPUs, rustc 1.99.0. Medians of seven samples, 100 rounds each, alternating baseline/candidate order and discarding a warm-up pair. The tool compiles the actual old/current modules and their FxHasher with rustc -O, checks identical level checksums, and measures allocation/destruction as well as construction. Update timings include source cloning, sorting, deduplication and Arc handling. Moving cases alternate adjacent chunk positions. Stationary cases exercise the existing unchanged-source cache.

Timing uses single-thread process CPU time (clock() on this POSIX host), excluding descheduling. All timings below are isolated ticket-map CPU milliseconds, not server MSPT.

Players Spacing (blocks) View/sim distance Build: before → after One player moves: before → after All players move: before → after
1 48 10 0.0006 → 0.0006 0.0007 → 0.0007 0.0006 → 0.0006
100 48 10 0.0518 → 0.0549 0.0524 → 0.0552 0.0524 → 0.0553
100 2400 10 1.2498 → 0.1224 0.8019 → 0.1228 0.7993 → 0.1235
100 1200 32 10.9035 → 1.0172 8.2132 → 0.9703 8.0401 → 0.9701

At 100 players / 2,400-block spacing / distance 10, construction is 10.2× faster and moving-source updates are about 6.5× faster. Lookup CPU time is 0.3576 → 0.3726 ms per 62,500 queries. The clustered cases retain the dense path and are included as controls. The tool also measures the unchanged-source cache path.

Also exercised real dedicated servers with 100 survival bots spread 2,400 blocks apart, view/simulation distance 10, flat terrain and exploration. All 100 remained connected in both builds. Those shared-machine runs had substantial tick-time/workload variation and do not establish an overall MSPT improvement. They are load smoke tests and a worker-utilisation check, not evidence of a whole-server speedup.

Other candidates considered

  • Generation and lighting already use the shared worker pool; dedicated servers already disable chunk meshing. The load runs were dominated by the tick thread, while aggregate generation/encoding worker CPU use was low. More worker threads would not address that workload.
  • Encoding sections/heightmaps, packet compression and region writes already have background paths. Retained the existing scheduling; no evidence here justifies another pool or moving mod callbacks off their thread.
  • Incremental ticket updates would add overlap/removal bookkeeping. First remove the much cheaper-to-fix per-chunk hash construction cost; the new rebuild takes about 0.12 ms in the target microbenchmark.
  • Chunk-send budgets, view-queue changes, entity-state caching and parallel simulation are left for separately profiled changes. This PR changes only the ticket representation, with no tick reordering or RNG changes.

Kind

  • perf: faster, or less memory

Vanilla reference

DistanceManager.getPlayerTicketLevel, getChunkLevel, inEntityTickingRange, inBlockTickingRange; ChunkTracker.getComputedLevel, inspected with tools/rea_vanilla.py. Loading/simulation minima and ticket reach are unchanged. The pre-existing scalar map is retained under cfg(test) as the reference, and the new test compares all cells, including tile padding, for mixed player/forced/portal sources, overlaps, negative coordinates and distance extremes. Existing tests also cover far coordinates, source invalidation and random-tick bounds.

Other projects' code

None.

Self-check

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at f1d6576b3, 8 min 15 s)

Check Result
Scope ✅ 2 files, +264 −8
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (42 s)
rustfmt ✅ (9 s)
clippy ✅ (1 s)
tests: horizon-client-lib ✅ 1476 passed (6 min 27 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 236 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 224 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Additional local checks:

  • Dedicated-server parity: 601 transcript lines identical to vanilla; Horizon-client connection/chat/chunk checks passed.
  • Server-entity parity: 34 entities identical to vanilla.
  • Ticket tests in the debug build: 9 passed, one existing benchmark ignored; signed-coordinate extremes included.

🤖 Generated with Codex.


🔄 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/7836 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `t3/dedicated-server-100-player-optimisations` --- ### 📝 Commits (1) - [`9e114dc`](https://github.com/horizon-rust/horizon/commit/9e114dc491a6065e27e4172c57d4ea7f694d9c0e) perf: tile sparse chunk ticket levels ### 📊 Changes **2 files changed** (+264 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/ticket_levels.rs` (+120 -8) ➕ `tools/bench_ticket_levels.py` (+144 -0) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Codex, gpt-6.1-sol), not by rdbtCVS personally. ## What and why With players far enough apart that the ticket bounding box no longer fits the dense grid, crossing a chunk boundary rebuilds a hash entry for every chunk in every player's ticket area. Store those levels in sparse 16×16 tiles instead: hash once per intersecting tile during construction, then lower the same loading and simulation levels in contiguous cells. Queries still hash once and index the cell. The dense-grid path and unchanged-source cache remain in place. Fixes #7814. Independent of #7719: no spawning, streaming-range, structure-cache or minecart changes are duplicated. ### Benchmark `taskset -c 11 python3 tools/bench_ticket_levels.py --base f1d6576b3 --rounds 100 --output tickets.json` Linux x86_64, 6 physical / 12 logical CPUs, rustc 1.99.0. Medians of seven samples, 100 rounds each, alternating baseline/candidate order and discarding a warm-up pair. The tool compiles the actual old/current modules and their FxHasher with `rustc -O`, checks identical level checksums, and measures allocation/destruction as well as construction. Update timings include source cloning, sorting, deduplication and Arc handling. Moving cases alternate adjacent chunk positions. Stationary cases exercise the existing unchanged-source cache. Timing uses single-thread process CPU time (`clock()` on this POSIX host), excluding descheduling. All timings below are **isolated ticket-map CPU milliseconds, not server MSPT**. | Players | Spacing (blocks) | View/sim distance | Build: before → after | One player moves: before → after | All players move: before → after | |---|---|---|---|---|---| | 1 | 48 | 10 | 0.0006 → 0.0006 | 0.0007 → 0.0007 | 0.0006 → 0.0006 | | 100 | 48 | 10 | 0.0518 → 0.0549 | 0.0524 → 0.0552 | 0.0524 → 0.0553 | | 100 | 2400 | 10 | 1.2498 → 0.1224 | 0.8019 → 0.1228 | 0.7993 → 0.1235 | | 100 | 1200 | 32 | 10.9035 → 1.0172 | 8.2132 → 0.9703 | 8.0401 → 0.9701 | At 100 players / 2,400-block spacing / distance 10, construction is 10.2× faster and moving-source updates are about 6.5× faster. Lookup CPU time is 0.3576 → 0.3726 ms per 62,500 queries. The clustered cases retain the dense path and are included as controls. The tool also measures the unchanged-source cache path. Also exercised real dedicated servers with 100 survival bots spread 2,400 blocks apart, view/simulation distance 10, flat terrain and exploration. All 100 remained connected in both builds. Those shared-machine runs had substantial tick-time/workload variation and do **not** establish an overall MSPT improvement. They are load smoke tests and a worker-utilisation check, not evidence of a whole-server speedup. ### Other candidates considered - Generation and lighting already use the shared worker pool; dedicated servers already disable chunk meshing. The load runs were dominated by the tick thread, while aggregate generation/encoding worker CPU use was low. More worker threads would not address that workload. - Encoding sections/heightmaps, packet compression and region writes already have background paths. Retained the existing scheduling; no evidence here justifies another pool or moving mod callbacks off their thread. - Incremental ticket updates would add overlap/removal bookkeeping. First remove the much cheaper-to-fix per-chunk hash construction cost; the new rebuild takes about 0.12 ms in the target microbenchmark. - Chunk-send budgets, view-queue changes, entity-state caching and parallel simulation are left for separately profiled changes. This PR changes only the ticket representation, with no tick reordering or RNG changes. ## Kind - [x] perf: faster, or less memory ## Vanilla reference `DistanceManager.getPlayerTicketLevel`, `getChunkLevel`, `inEntityTickingRange`, `inBlockTickingRange`; `ChunkTracker.getComputedLevel`, inspected with `tools/rea_vanilla.py`. Loading/simulation minima and ticket reach are unchanged. The pre-existing scalar map is retained under `cfg(test)` as the reference, and the new test compares all cells, including tile padding, for mixed player/forced/portal sources, overlaps, negative coordinates and distance extremes. Existing tests also cover far coordinates, source invalidation and random-tick bounds. ## Other projects' code None. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at f1d6576b3, 8 min 15 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +264 −8 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (42 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (1 s) | | tests: horizon-client-lib | ✅ 1476 passed (6 min 27 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 236 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 224 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Additional local checks: - Dedicated-server parity: 601 transcript lines identical to vanilla; Horizon-client connection/chat/chunk checks passed. - Server-entity parity: 34 entities identical to vanilla. - Ticket tests in the debug build: 9 passed, one existing benchmark ignored; signed-coordinate extremes included. 🤖 Generated with [Codex](https://openai.com/codex/). --- <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#7852
No description provided.