[PR #3827] [MERGED] perf(client): eliminate main-thread tick stutter at high render distances #5238

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

📋 Pull Request Information

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

Base: main ← Head: perf/rd32-tick-stutter


📝 Commits (3)

  • 4dca273 perf(client): avoid O(N) SipHash scan in TickChunkMembership::synchronize
  • a368ded perf(client): restrict tick_blocks candidate lookup to random-ticking bounds
  • 6ec32c5 perf(client): index fresh chunks in ChunkMap instead of scanning all columns

📊 Changes

5 files changed (+448 additions, -18 deletions)

View changed files

📝 crates/horizon-client-render/src/chunk_map.rs (+260 -3)
📝 crates/horizon-client/src/game.rs (+26 -3)
📝 crates/horizon-client/src/game/creatures.rs (+7 -3)
📝 crates/horizon-client/src/tick_chunk_membership.rs (+77 -6)
📝 crates/horizon-client/src/ticket_levels.rs (+78 -3)

📄 Description

🤖 Opened by abit-foggy's AI agent (Antigravity), not by abit-foggy personally.

What and why

Eliminates the game-tick stutter at high render distances (e.g. Render Distance 32 with 4,225 chunks) caused by main-thread chunk table scans and membership synchronization:

  1. Incremental Tick Chunk Synchronization:
    • Added an incremental delta ring buffer (recent_deltas) in ChunkMap recording recent chunk additions and removals.
    • Converted TickChunkMembership to FxHashSet and implemented incremental delta replay, reducing streaming churn synchronization from 122.47 µs to 0.60 µs (204x faster).
  2. Spatial Bounding in tick_blocks Candidate Selection:
    • Precomputes random_tick_bounds on ticket updates in Levels.
    • Filters candidate chunks against spatial simulation bounds before evaluating ticket levels, and avoids redundant center chunk lookups in ticking_chunk. Retains identical chunk iteration order from world.chunks.keys().copied() for deterministic RNG and precipitation parity.
  3. Indexed Fresh Chunk Tracking:
    • Maintains fresh: FxHashSet<Key> inside ChunkMap across insert, remove, and clear.
    • Replaces the O(N) full-table scan in tick_creatures with an O(1) has_fresh() check and indexed key iterations, eliminating 18.38 µs of stall per tick during steady-state gameplay.

Benchmark Results (Render Distance 32: 4,225 loaded chunks)

Benchmark Baseline (before) Optimized (after) Improvement
TickChunkMembership::synchronize 122.47 µs/sync 0.60 µs/sync 204.1x faster (99.5% reduction)
tick_blocks candidate selection 51.30 µs/tick 38.73 µs/tick 1.32x faster (24.5% reduction)
tick_creatures fresh-chunk scan 18.38 µs/tick 0.00 µs/tick Eliminated in steady state

Vanilla reference

Follows vanilla 26.3 ServerChunkCache.tickChunks, DistanceManager.inEntityTickingRange, and NaturalSpawner.
Maintains 100% vanilla simulation parity: zero change to RNG draw order, entity despawn rules, or tick timing.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on foggy-MacBookPro, against upstream/main at d009ebd14, 4 min 35 s)

Check Result
Scope ✅ 5 files, +195 −24
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 423 passed (41 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 23 s)
tests: horizon-client, horizon-client-render ✅ 1417 passed (1 min 46 s)
doc tests ✅ 0 passed (37 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 ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 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/3827 **Author:** [@abit-foggy](https://github.com/abit-foggy) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/rd32-tick-stutter` --- ### 📝 Commits (3) - [`4dca273`](https://github.com/horizon-rust/horizon/commit/4dca2732a334e32f9e760cf99b3bc67f516cb1c3) perf(client): avoid O(N) SipHash scan in TickChunkMembership::synchronize - [`a368ded`](https://github.com/horizon-rust/horizon/commit/a368ded7f585377163a363562d8138ffbd8dd486) perf(client): restrict tick_blocks candidate lookup to random-ticking bounds - [`6ec32c5`](https://github.com/horizon-rust/horizon/commit/6ec32c5ec74a46331f2cc5002c56e4dd19e4b7be) perf(client): index fresh chunks in ChunkMap instead of scanning all columns ### 📊 Changes **5 files changed** (+448 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/chunk_map.rs` (+260 -3) 📝 `crates/horizon-client/src/game.rs` (+26 -3) 📝 `crates/horizon-client/src/game/creatures.rs` (+7 -3) 📝 `crates/horizon-client/src/tick_chunk_membership.rs` (+77 -6) 📝 `crates/horizon-client/src/ticket_levels.rs` (+78 -3) </details> ### 📄 Description > 🤖 Opened by abit-foggy's AI agent (Antigravity), not by abit-foggy personally. ## What and why Eliminates the game-tick stutter at high render distances (e.g. Render Distance 32 with 4,225 chunks) caused by main-thread chunk table scans and membership synchronization: 1. **Incremental Tick Chunk Synchronization:** - Added an incremental delta ring buffer (`recent_deltas`) in `ChunkMap` recording recent chunk additions and removals. - Converted `TickChunkMembership` to `FxHashSet` and implemented incremental delta replay, reducing streaming churn synchronization from 122.47 µs to 0.60 µs (204x faster). 2. **Spatial Bounding in `tick_blocks` Candidate Selection:** - Precomputes `random_tick_bounds` on ticket updates in `Levels`. - Filters candidate chunks against spatial simulation bounds before evaluating ticket levels, and avoids redundant center chunk lookups in `ticking_chunk`. Retains identical chunk iteration order from `world.chunks.keys().copied()` for deterministic RNG and precipitation parity. 3. **Indexed Fresh Chunk Tracking:** - Maintains `fresh: FxHashSet<Key>` inside `ChunkMap` across `insert`, `remove`, and `clear`. - Replaces the $O(N)$ full-table scan in `tick_creatures` with an $O(1)$ `has_fresh()` check and indexed key iterations, eliminating 18.38 µs of stall per tick during steady-state gameplay. ### Benchmark Results (Render Distance 32: 4,225 loaded chunks) | Benchmark | Baseline (`before`) | Optimized (`after`) | Improvement | | :--- | :--- | :--- | :--- | | `TickChunkMembership::synchronize` | 122.47 µs/sync | 0.60 µs/sync | **204.1x faster** (99.5% reduction) | | `tick_blocks` candidate selection | 51.30 µs/tick | 38.73 µs/tick | **1.32x faster** (24.5% reduction) | | `tick_creatures` fresh-chunk scan | 18.38 µs/tick | 0.00 µs/tick | **Eliminated** in steady state | ## Vanilla reference Follows vanilla 26.3 `ServerChunkCache.tickChunks`, `DistanceManager.inEntityTickingRange`, and `NaturalSpawner`. Maintains 100% vanilla simulation parity: zero change to RNG draw order, entity despawn rules, or tick timing. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on foggy-MacBookPro, against upstream/main at d009ebd14, 4 min 35 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +195 −24 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 423 passed (41 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 23 s) | | tests: horizon-client, horizon-client-render | ✅ 1417 passed (1 min 46 s) | | doc tests | ✅ 0 passed (37 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 | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:11:10 +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#5238
No description provided.