[PR #914] [MERGED] Guest ticks: count per-tick statistics without making strings, date criteria only when granted #2909

Closed
opened 2026-11-02 16:00:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/guest-tick-stats


📝 Commits (1)

  • 02a6ab7 Guest ticks: count the per-tick statistics without making strings, and date a criterion only when one is granted

📊 Changes

2 files changed (+99 additions, -17 deletions)

View changed files

📝 crates/horizon-client/src/game/advancements.rs (+3 -0)
📝 crates/horizon-client/src/game/stats.rs (+96 -17)

📄 Description

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

What

Two per-tick costs in every player's server tick (tick_guests) are cut:

  • Statistics (ServerStatsCounter): Stats::add and Stats::custom built about seven strings per call (format!("minecraft:{ty}") three times, the key three times, custom's namespaced key), and count_tick_stats makes four or five of these calls for every player on every tick (play_time, total_world_time, time_since_death, time_since_rest, plus the movement counter). Now the namespaced names are put together on the stack, existing counters are found by &str, and the dirty set is kept per type (BTreeMap<type, BTreeSet<key>>), so an already-dirty counter is found without a string made for it. Only the event for the scoreboard criteria still owns its two strings.
  • Advancements: trigger read the clock and formatted the criterion date (now_text) on every call, even when nothing was granted. minecraft:tick triggers every tick for every player. The date is now made only when a criterion is granted.

Values, events and dirty entries are the same, in the same order. take_dirty still yields them sorted by (type, key), and the new test checks that.

Why

Brief perf-server-10, task 2: of the two tick_lan costs perf-server-9 listed, take the bigger. In a 30 s sample of the base server under 40 walking bots (Mac mini), tick_guests had 186 of tick_lan's 1101 samples and lan_entities had 7. Inside tick_guests: count_tick_stats 43, Stats::add 31, fmt::format 32 (overlapping), tick_advancements 44, about 16 of them in the clock read and date formatting.

Numbers

Microbenchmark of the per-tick counters (the old and new Stats code copied side by side, a stats map with 120 other counters, minimum of 20 rounds, M4 Pro):

per player per tick (5 counters) before after
time 1169 ns 621 ns (-47%)

At 40 players that is about 47 µs down to 25 µs per tick for the counters. Each trigger call that grants nothing also skips a clock read and a date format.

Checks

On the integration commit fa1cec37 (this branch merged with perf/paletted-pack and perf/chunk-encode-workers on origin/main 87cf8cb9):

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: 881 lib + 76 bin + integration tests pass. The new game::stats::tests::counters_events_and_dirty_entries passes.
  • Parity: scoreboard (stats events feed its criteria), lan, dedicated_server, server_world_gen, chunk_stage, world_reopen: 6 passed, 0 failed. CI parity covers the rest of --changed.

Needs Ludovic

Nothing.

🤖 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/914 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/guest-tick-stats` --- ### 📝 Commits (1) - [`02a6ab7`](https://github.com/horizon-rust/horizon/commit/02a6ab7429cbb4de63c8f0e7abc3708aac9e2c95) Guest ticks: count the per-tick statistics without making strings, and date a criterion only when one is granted ### 📊 Changes **2 files changed** (+99 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/advancements.rs` (+3 -0) 📝 `crates/horizon-client/src/game/stats.rs` (+96 -17) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Two per-tick costs in every player's server tick (`tick_guests`) are cut: - **Statistics** (`ServerStatsCounter`): `Stats::add` and `Stats::custom` built about seven strings per call (`format!("minecraft:{ty}")` three times, the key three times, `custom`'s namespaced key), and `count_tick_stats` makes four or five of these calls for every player on every tick (`play_time`, `total_world_time`, `time_since_death`, `time_since_rest`, plus the movement counter). Now the namespaced names are put together on the stack, existing counters are found by `&str`, and the dirty set is kept per type (`BTreeMap<type, BTreeSet<key>>`), so an already-dirty counter is found without a string made for it. Only the event for the scoreboard criteria still owns its two strings. - **Advancements**: `trigger` read the clock and formatted the criterion date (`now_text`) on every call, even when nothing was granted. `minecraft:tick` triggers every tick for every player. The date is now made only when a criterion is granted. Values, events and dirty entries are the same, in the same order. `take_dirty` still yields them sorted by (type, key), and the new test checks that. ## Why Brief perf-server-10, task 2: of the two `tick_lan` costs perf-server-9 listed, take the bigger. In a 30 s `sample` of the base server under 40 walking bots (Mac mini), `tick_guests` had 186 of `tick_lan`'s 1101 samples and `lan_entities` had 7. Inside `tick_guests`: `count_tick_stats` 43, `Stats::add` 31, `fmt::format` 32 (overlapping), `tick_advancements` 44, about 16 of them in the clock read and date formatting. ## Numbers Microbenchmark of the per-tick counters (the old and new `Stats` code copied side by side, a stats map with 120 other counters, minimum of 20 rounds, M4 Pro): | per player per tick (5 counters) | before | after | |---|---|---| | time | 1169 ns | 621 ns (-47%) | At 40 players that is about 47 µs down to 25 µs per tick for the counters. Each `trigger` call that grants nothing also skips a clock read and a date format. ## Checks On the integration commit fa1cec37 (this branch merged with perf/paletted-pack and perf/chunk-encode-workers on origin/main 87cf8cb9): - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: 881 lib + 76 bin + integration tests pass. The new `game::stats::tests::counters_events_and_dirty_entries` passes. - Parity: `scoreboard` (stats events feed its criteria), `lan`, `dedicated_server`, `server_world_gen`, `chunk_stage`, `world_reopen`: 6 passed, 0 failed. CI parity covers the rest of `--changed`. ## Needs Ludovic Nothing. 🤖 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-02 16:00:01 +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#2909
No description provided.