[PR #4535] [MERGED] Creaking hearts: snapshot the other mobs only on the ticks that read them (−3 ms/tick on a busy server) #5680

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

📋 Pull Request Information

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

Base: main ← Head: perf/creaking-heart-snapshot


📝 Commits (2)

  • aa906ec Creaking hearts: build the other mobs only on the ticks that read them
  • d52d37f Merge main into perf/creaking-heart-snapshot

📊 Changes

2 files changed (+21 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game/creaking.rs (+14 -6)
📝 crates/horizon-client/src/mobs/creaking_heart.rs (+7 -0)

📄 Description

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

Why

On a busy dedicated server, tick_block_entities took 5–6 ms of every tick. Much of that was creaking hearts: with_heart built a snapshot of every mob in the level, for every heart, on every tick. The snapshot is only read on the ticks a heart actually updates, and when its creaking is hurt.

What

  • creaking_heart::tick_updates(&heart) says whether this tick's CreakingHeartBlockEntity.serverTick gets past its countdown.
  • with_heart takes an others flag:
    • the tick passes tick_updates;
    • creaking_hurt passes true;
    • remove_protector passes false, because it reads no other mob.
  • When the flag is false, the snapshot is empty. Behaviour is unchanged: the countdown ticks read no mob.

Proof

60 bots (horizon-bots' server mix: settling, a town, explorers capped at 10 blocks/s, building, chat) ran on playhorizon, pinned to CPUs 0–3 (exclusive), fast profile. Three interleaved rounds against the same base (main at fca2169de), 60 s each after warm-up:

Round Build TPS MSPT avg p95 p99 ticks > 100 ms tick_block_entities ms/tick
1 base 9.54 104.8 121.1 131.1 598 5.95
1 this 9.86 101.3 113.6 123.0 463 2.91
2 base 9.33 107.2 122.9 134.6 672 5.91
2 this 9.86 101.5 116.4 129.5 465 2.74
3 base 9.62 104.1 121.5 134.4 583 5.24
3 this 10.53 95.0 107.2 115.6 162 2.39

tick_block_entities drops by about 3 ms per tick in every round (5.7 → 2.7 ms on average), and average MSPT drops by 3.5 to 9 ms.

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 91352551d, 9 min 46 s)

Check Result
Scope ✅ 2 files, +21 −6
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 3 s)
rustfmt ✅ (4 s)
clippy ✅ (2 min 36 s)
tests: horizon-client ✅ 1065 passed (5 min 24 s)
doc tests ✅ 0 passed (2 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 ➖ 34 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 22 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/4535 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/creaking-heart-snapshot` --- ### 📝 Commits (2) - [`aa906ec`](https://github.com/horizon-rust/horizon/commit/aa906ecbe78b904ddd968e91b24fbc256b2bd3f6) Creaking hearts: build the other mobs only on the ticks that read them - [`d52d37f`](https://github.com/horizon-rust/horizon/commit/d52d37f9446c0e540e9087c85cb2239155072d09) Merge main into perf/creaking-heart-snapshot ### 📊 Changes **2 files changed** (+21 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creaking.rs` (+14 -6) 📝 `crates/horizon-client/src/mobs/creaking_heart.rs` (+7 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## Why On a busy dedicated server, `tick_block_entities` took 5–6 ms of every tick. Much of that was creaking hearts: `with_heart` built a snapshot of every mob in the level, for every heart, on every tick. The snapshot is only read on the ticks a heart actually updates, and when its creaking is hurt. ## What - `creaking_heart::tick_updates(&heart)` says whether this tick's `CreakingHeartBlockEntity.serverTick` gets past its countdown. - `with_heart` takes an `others` flag: - the tick passes `tick_updates`; - `creaking_hurt` passes `true`; - `remove_protector` passes `false`, because it reads no other mob. - When the flag is false, the snapshot is empty. Behaviour is unchanged: the countdown ticks read no mob. ## Proof 60 bots (horizon-bots' `server` mix: settling, a town, explorers capped at 10 blocks/s, building, chat) ran on playhorizon, pinned to CPUs 0–3 (exclusive), fast profile. Three interleaved rounds against the same base (main at fca2169de), 60 s each after warm-up: | Round | Build | TPS | MSPT avg | p95 | p99 | ticks > 100 ms | `tick_block_entities` ms/tick | |---|---|---|---|---|---|---|---| | 1 | base | 9.54 | 104.8 | 121.1 | 131.1 | 598 | 5.95 | | 1 | this | 9.86 | 101.3 | 113.6 | 123.0 | 463 | 2.91 | | 2 | base | 9.33 | 107.2 | 122.9 | 134.6 | 672 | 5.91 | | 2 | this | 9.86 | 101.5 | 116.4 | 129.5 | 465 | 2.74 | | 3 | base | 9.62 | 104.1 | 121.5 | 134.4 | 583 | 5.24 | | 3 | this | 10.53 | 95.0 | 107.2 | 115.6 | 162 | 2.39 | `tick_block_entities` drops by about 3 ms per tick in every round (5.7 → 2.7 ms on average), and average MSPT drops by 3.5 to 9 ms. **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 91352551d, 9 min 46 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +21 −6 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 3 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (2 min 36 s) | | tests: horizon-client | ✅ 1065 passed (5 min 24 s) | | doc tests | ✅ 0 passed (2 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 | ➖ 34 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 22 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 05:14:18 +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#5680
No description provided.