[PR #5565] [MERGED] Random ticks: skip the drawn blocks that can't tick (−52 % random-tick time at 20 players) #6356

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

📋 Pull Request Information

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

Base: main ← Head: perf/random-tick-masks


📝 Commits (2)

  • 3dbe978 Random ticks: skip the drawn blocks that can't tick, from a per-section mask
  • 8c93623 Random ticks: their own span

📊 Changes

4 files changed (+191 additions, -29 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+28 -19)
📝 crates/horizon-client/src/random_tick_sections.rs (+94 -7)
📝 crates/horizon-world/src/level/mod.rs (+1 -1)
📝 crates/horizon-world/src/level/tick.rs (+68 -2)

📄 Description

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

At 20 players, Horizon's server ticks in 36 ms where Pumpkin takes 20 (docs/performance/server-vs-pumpkin.md). Random block ticks were the second biggest part of a tick: 5.6–6.6 ms at 20 bots on playhorizon.

Vanilla draws randomTickSpeed positions in every section that holds a randomly ticking block, and reads the block at each one. Most of those blocks are stone, dirt or air, and each read is a chain of cache misses: the chunk map, the section, its palette, its words, then the block's facts. This change keeps, for each ticking section, a 4,096-bit mask of the blocks a random tick can do anything for (a randomly ticking block, or lava for its fluid tick). A drawn position outside the mask is not read.

What stays the same:

  • Every draw happens, in the same order: the mask only decides whether the drawn block is read.
  • Every tick that runs still runs: random_tick_at does nothing for a block that is neither randomly ticking nor lava (Behaviours::random_tick_candidate says which).
  • A mask is built at the section's first draw and dropped when the section changes (RandomTickSections already tells an edited section by its pointer). After a draw that ticked, the section is asked for again, so the next draws see the blocks as they are now.

The masks cost 528 bytes per ticking section: RSS under load didn't move (table).

The random ticks also get their own span, random_ticks.

Measured

playhorizon (EPYC 7662), CPUs 0–3 to the run, release builds, 20 mixed bots, seed 12345, view and simulation distance 10, 60 s warm-up then 120 s, tools/server_bench.py with HORIZON_SPIKES=0. Three rounds, the builds alternated. Base: main at 21bddafb2 with only the random_ticks span added (bench/sp2-rt-span 51400dae1); change: 4b632ff5a (this branch before its rebase).

ms per tick base 1 base 2 base 3 change 1 change 2 change 3 median
random_ticks 5.60 5.75 6.60 2.77 2.78 3.09 5.75 → 2.78 (−52 %)
tick_blocks 8.36 8.57 9.54 5.61 5.59 6.17 8.57 → 5.61 (−35 %)
MSPT avg (tick query) 30.3 34.6 32.5 28.0 30.1 33.3 32.5 → 30.1
RSS mean MB 1194 1180 1198 1195 1182 1192 same

MSPT moves with the mob count and the shared host's load (round 3's change run had tick_mobs at 12.3 against 9.4); the spans of the changed code are steady.

On the Mac mini (fast builds, 2 pairs): random_ticks 1.69 / 1.82 → 1.17 / 1.13 ms.

Checks

  • random_tick_sections::tick_parity::actual_random_ticks_match_a_block_scan now runs the masked path beside the reference scan for 128 ticks (edits, replaced sections, unloads, a changed random-ticks fact): the same events, the same position and level RNG, the same blocks.
  • Harnesses here: random_tick_sections PASS. random_tick has one differing case, a scheduled tick of dirt_path (push_entities_up): that harness runs Behaviours::random_tick/tick_block per state, which this change doesn't touch. The other affected harnesses run in CI (run-parity).

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 23cd6895b, 15 min 45 s)

Check Result
Scope ✅ 4 files, +191 −29
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 510 passed (2 min 42 s)
rustfmt ✅ (5 s)
clippy ✅ (2 min 46 s)
tests: horizon-client, horizon-world ✅ 1927 passed (9 min 56 s)
doc tests ✅ 0 passed (4 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 ➖ 134 affected, to run in CI (--quick): ambient_sound, arrow, attribute_updates, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 122 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/5565 **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/random-tick-masks` --- ### 📝 Commits (2) - [`3dbe978`](https://github.com/horizon-rust/horizon/commit/3dbe97809f528965d17a64899456ebf31aef70db) Random ticks: skip the drawn blocks that can't tick, from a per-section mask - [`8c93623`](https://github.com/horizon-rust/horizon/commit/8c936237a8ed355c1d14794b43ed4582377ef5df) Random ticks: their own span ### 📊 Changes **4 files changed** (+191 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+28 -19) 📝 `crates/horizon-client/src/random_tick_sections.rs` (+94 -7) 📝 `crates/horizon-world/src/level/mod.rs` (+1 -1) 📝 `crates/horizon-world/src/level/tick.rs` (+68 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. At 20 players, Horizon's server ticks in 36 ms where Pumpkin takes 20 (docs/performance/server-vs-pumpkin.md). Random block ticks were the second biggest part of a tick: 5.6–6.6 ms at 20 bots on playhorizon. Vanilla draws `randomTickSpeed` positions in every section that holds a randomly ticking block, and reads the block at each one. Most of those blocks are stone, dirt or air, and each read is a chain of cache misses: the chunk map, the section, its palette, its words, then the block's facts. This change keeps, for each ticking section, a 4,096-bit mask of the blocks a random tick can do anything for (a randomly ticking block, or lava for its fluid tick). A drawn position outside the mask is not read. What stays the same: - Every draw happens, in the same order: the mask only decides whether the drawn block is read. - Every tick that runs still runs: `random_tick_at` does nothing for a block that is neither randomly ticking nor lava (`Behaviours::random_tick_candidate` says which). - A mask is built at the section's first draw and dropped when the section changes (`RandomTickSections` already tells an edited section by its pointer). After a draw that ticked, the section is asked for again, so the next draws see the blocks as they are now. The masks cost 528 bytes per ticking section: RSS under load didn't move (table). The random ticks also get their own span, `random_ticks`. ## Measured playhorizon (EPYC 7662), CPUs 0–3 to the run, release builds, 20 `mixed` bots, seed 12345, view and simulation distance 10, 60 s warm-up then 120 s, `tools/server_bench.py` with `HORIZON_SPIKES=0`. Three rounds, the builds alternated. Base: main at 21bddafb2 with only the `random_ticks` span added (bench/sp2-rt-span 51400dae1); change: 4b632ff5a (this branch before its rebase). | ms per tick | base 1 | base 2 | base 3 | change 1 | change 2 | change 3 | median | |---|---:|---:|---:|---:|---:|---:|---| | `random_ticks` | 5.60 | 5.75 | 6.60 | 2.77 | 2.78 | 3.09 | 5.75 → 2.78 (−52 %) | | `tick_blocks` | 8.36 | 8.57 | 9.54 | 5.61 | 5.59 | 6.17 | 8.57 → 5.61 (−35 %) | | MSPT avg (`tick query`) | 30.3 | 34.6 | 32.5 | 28.0 | 30.1 | 33.3 | 32.5 → 30.1 | | RSS mean MB | 1194 | 1180 | 1198 | 1195 | 1182 | 1192 | same | MSPT moves with the mob count and the shared host's load (round 3's change run had `tick_mobs` at 12.3 against 9.4); the spans of the changed code are steady. On the Mac mini (fast builds, 2 pairs): `random_ticks` 1.69 / 1.82 → 1.17 / 1.13 ms. ## Checks - `random_tick_sections::tick_parity::actual_random_ticks_match_a_block_scan` now runs the masked path beside the reference scan for 128 ticks (edits, replaced sections, unloads, a changed random-ticks fact): the same events, the same position and level RNG, the same blocks. - Harnesses here: `random_tick_sections` PASS. `random_tick` has one differing case, a scheduled `tick` of `dirt_path` (`push_entities_up`): that harness runs `Behaviours::random_tick`/`tick_block` per state, which this change doesn't touch. The other affected harnesses run in CI (`run-parity`). **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 23cd6895b, 15 min 45 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +191 −29 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 510 passed (2 min 42 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (2 min 46 s) | | tests: horizon-client, horizon-world | ✅ 1927 passed (9 min 56 s) | | doc tests | ✅ 0 passed (4 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 | ➖ 134 affected, to run in CI (--quick): ambient_sound, arrow, attribute_updates, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 122 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:19:08 +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#6356
No description provided.