[PR #7653] [MERGED] perf(client): Efficient pacing keeps frames on a fixed grid of slots #7740

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7653
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/limiter-grid


📝 Commits (1)

  • 2e06039 perf(client): Efficient pacing keeps frames on a fixed grid of slots

📊 Changes

4 files changed (+139 additions, -4 deletions)

View changed files

📝 crates/horizon-client-input/src/window.rs (+135 -1)
📝 crates/horizon-client-render/src/graphics.rs (+2 -1)
📝 crates/horizon-client/src/game/options.rs (+1 -1)
📝 docs/graphics.md (+1 -1)

📄 Description

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

What

Vanilla's FramerateLimiter starts each frame's slot when the thread wakes up, so every late wake-up adds to that frame's length. Horizon's Efficient pacing (the default) finishes its wait with 50 µs sleeps, which run late on a loaded Mac. A cap of 140 gave 139.3 FPS on average.

Efficient pacing now uses FramerateLimiter::limit_on_grid:

  • On time: each slot ends at its deadline instead of at the wake-up time, so the cap holds on average.
  • Late: a frame that ends past its slot, or wakes up more than half a frame late, starts the grid again from now. No frame is rushed out to catch up, so no burst after a long frame.

The wait itself is the same code as vanilla's (wait_until, split out of limit_display_fps). Precise pacing, which is vanilla's limiter, is unchanged. Docs (docs/graphics.md, the Pacing doc) say so.

A/B

--max-fps 144, which loads as 140 (vanilla's options keep multiples of 10). RD 16, offscreen, 3 alternated pairs (main / this PR) on the Mac mini:

scenario build avg FPS p50 p99 p99.9 1% low
elytra main 139.3–139.4 7.17–7.18 7.22–7.23 7.24–7.77 134.9–138.3
elytra PR 140.0 7.14 7.21–7.23 7.22–7.67 134.3–138.6
fly64 main 139.3 7.18 7.22–7.24 7.25–7.62 133.6–138.2
fly64 PR 139.7–140.0 7.14 7.21 7.24–7.26 114.5–138.4

The PR's 114.5 1% low is one fly64 run with a single 70 ms frame. Its spans weren't kept, and the run's CPU frame stats stay low, so I put it down to the loaded Mac. The lows are otherwise equal within noise.

Tests

  • the_grid_holds_the_cap_when_wake_ups_run_late: with sleeps that run up to 0 / 50 / 200 / 1000 µs late (pseudo-random), the grid's mean period stays within 10 µs of 1/144 s, and no slot is shorter than half a frame. Vanilla's way, with sleeps up to 400 µs late, averages more than 50 µs above the period.
  • a_long_frame_starts_the_grid_again_without_a_burst: after a 30 ms frame, every following slot is a full period (± the 50 µs lateness). No frames are rushed out to catch up.

pr_ready

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 0041483e9, 11 min 19 s)

Check Result
Scope ✅ 4 files, +139 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 15 s)
rustfmt ✅ (15 s)
clippy ✅ (2 min 22 s)
tests: horizon-client, horizon-client-input, horizon-client-render ❌ 769 passed (6 min 3 s)
doc tests ✅ 0 passed (5 s)
content root tests ➖ content root untouched
mod API up to date ✅ (47 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 141 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 129 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The ❌ is the known llvmpipe SIGSEGV of horizon-client-render's lib tests in parallel. Rerun on the same checkout:

  • horizon-client-render --lib --test-threads=1: 1163 passed
  • horizon-client-input --lib: 70 passed
  • horizon-client --lib --bins --tests: 693 + 5 passed, 0 failed

🤖 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/7653 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/limiter-grid` --- ### 📝 Commits (1) - [`2e06039`](https://github.com/horizon-rust/horizon/commit/2e0603943881c12b313a94d87b602a621c3898f1) perf(client): Efficient pacing keeps frames on a fixed grid of slots ### 📊 Changes **4 files changed** (+139 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-input/src/window.rs` (+135 -1) 📝 `crates/horizon-client-render/src/graphics.rs` (+2 -1) 📝 `crates/horizon-client/src/game/options.rs` (+1 -1) 📝 `docs/graphics.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Vanilla's `FramerateLimiter` starts each frame's slot when the thread wakes up, so every late wake-up adds to that frame's length. Horizon's Efficient pacing (the default) finishes its wait with 50 µs sleeps, which run late on a loaded Mac. A cap of 140 gave 139.3 FPS on average. Efficient pacing now uses `FramerateLimiter::limit_on_grid`: - **On time:** each slot ends at its deadline instead of at the wake-up time, so the cap holds on average. - **Late:** a frame that ends past its slot, or wakes up more than half a frame late, starts the grid again from now. No frame is rushed out to catch up, so no burst after a long frame. The wait itself is the same code as vanilla's (`wait_until`, split out of `limit_display_fps`). Precise pacing, which is vanilla's limiter, is unchanged. Docs (`docs/graphics.md`, the `Pacing` doc) say so. ## A/B `--max-fps 144`, which loads as 140 (vanilla's options keep multiples of 10). RD 16, offscreen, 3 alternated pairs (main / this PR) on the Mac mini: | scenario | build | avg FPS | p50 | p99 | p99.9 | 1% low | |---|---|---|---|---|---|---| | elytra | main | 139.3–139.4 | 7.17–7.18 | 7.22–7.23 | 7.24–7.77 | 134.9–138.3 | | elytra | PR | 140.0 | 7.14 | 7.21–7.23 | 7.22–7.67 | 134.3–138.6 | | fly64 | main | 139.3 | 7.18 | 7.22–7.24 | 7.25–7.62 | 133.6–138.2 | | fly64 | PR | 139.7–140.0 | 7.14 | 7.21 | 7.24–7.26 | 114.5–138.4 | The PR's 114.5 1% low is one fly64 run with a single 70 ms frame. Its spans weren't kept, and the run's CPU frame stats stay low, so I put it down to the loaded Mac. The lows are otherwise equal within noise. ## Tests - `the_grid_holds_the_cap_when_wake_ups_run_late`: with sleeps that run up to 0 / 50 / 200 / 1000 µs late (pseudo-random), the grid's mean period stays within 10 µs of 1/144 s, and no slot is shorter than half a frame. Vanilla's way, with sleeps up to 400 µs late, averages more than 50 µs above the period. - `a_long_frame_starts_the_grid_again_without_a_burst`: after a 30 ms frame, every following slot is a full period (± the 50 µs lateness). No frames are rushed out to catch up. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 0041483e9, 11 min 19 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +139 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 15 s) | | rustfmt | ✅ (15 s) | | clippy | ✅ (2 min 22 s) | | tests: horizon-client, horizon-client-input, horizon-client-render | ❌ 769 passed (6 min 3 s) | | doc tests | ✅ 0 passed (5 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (47 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 141 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 129 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The ❌ is the known llvmpipe SIGSEGV of `horizon-client-render`'s lib tests in parallel. Rerun on the same checkout: - `horizon-client-render --lib --test-threads=1`: 1163 passed - `horizon-client-input --lib`: 70 passed - `horizon-client --lib --bins --tests`: 693 + 5 passed, 0 failed 🤖 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 07:23:26 +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#7740
No description provided.