[PR #7600] [MERGED] fix(client): a frame cap holds on macOS: the limiter sleeps in 1 ms steps #7707

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

📋 Pull Request Information

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

Base: main ← Head: fix/limiter-park-steps


📝 Commits (1)

  • 0bd491e fix(client): a frame cap holds on macOS: the limiter sleeps in 1 ms steps

📊 Changes

1 file changed (+68 additions, -1 deletions)

View changed files

📝 crates/horizon-client-input/src/window.rs (+68 -1)

📄 Description

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

What

With a frame cap, macOS frames ran late. At 60 FPS every frame took 17–20 ms instead of 16.7: about 57 FPS on average, with a 1% low of 50 FPS, which shows as judder. This happens even when the CPU only spends 2 ms per frame.

The cause is that macOS runs a sleep late by a share of its length (timer coalescing). Measured on the Mac mini:

requested sleep late by (p50 – p90)
50 µs 17–21 µs
1 ms 256–267 µs
2 ms 506–532 µs
14 ms (a 60 FPS frame's wait) 1.75–3.5 ms

The limiter (vanilla's FramerateLimiter) learns an overshoot margin, but caps it at 2 ms and averages it. It can't cover 3.5 ms of variable lateness, so each frame wakes up after its deadline.

SystemClock::park now sleeps at most 1 ms at a time until its deadline, so a frame can only be late by the last step's lateness. The limiter's logic is vanilla's and is not touched; both pacing modes (Precise and Efficient) use this clock. On Linux and Windows the steps change nothing they need: those sleeps were already precise.

A/B in game

60 FPS cap, RD 16, offscreen, 3 alternated pairs (main / this PR) on the loaded Mac mini:

scenario build p50 p99 p99.9 1% low 0.1% low avg FPS
elytra main 17.28–17.37 19.76–19.93 19.94–20.04 50.1–50.3 48.1–50.2 56.8–57.6
elytra PR 16.70 16.75–16.76 16.85–18.13 58.4–59.6 53.1–59.1 59.9
fly64 main 16.89–17.33 19.61–19.86 19.89–19.94 50.3–50.6 49.8–50.3 57.5–57.7
fly64 PR 16.70 16.75–16.77 16.83–16.90 59.4–59.5 57.6–59.0 59.9

I also ran a limiter alone in one process, alternating 6 rounds of each with 2 ms of work per frame, at 60 FPS on the same Mac (load ~29):

mode frames late by more than 1 ms p99
Precise 29.4 % → 2.0 % 21.3 → 18.8 ms
Efficient (default) 32.5 % → 13.6 % —

Test

a_frame_cap_holds_when_sleeps_run_late: a clock whose sleeps run 25 % late, sleeping as SystemClock::park does, keeps a 60 FPS cap within 0.1 ms of 16.67 ms on every frame. With one long sleep, the first frame already lands 3.5 ms late.

pr_ready

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at ae3cbb0f1, 4 min 14 s)

Check Result
Scope ✅ 1 files, +68 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 6 s)
rustfmt ✅ (14 s)
clippy ✅ (1 min 46 s)
tests: horizon-client-input ✅ 68 passed (34 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
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)

🤖 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/7600 **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:** `fix/limiter-park-steps` --- ### 📝 Commits (1) - [`0bd491e`](https://github.com/horizon-rust/horizon/commit/0bd491e762938edf5e2caab6ae30d767beab5979) fix(client): a frame cap holds on macOS: the limiter sleeps in 1 ms steps ### 📊 Changes **1 file changed** (+68 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-input/src/window.rs` (+68 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What With a frame cap, macOS frames ran late. At 60 FPS every frame took 17–20 ms instead of 16.7: about 57 FPS on average, with a 1% low of 50 FPS, which shows as judder. This happens even when the CPU only spends 2 ms per frame. The cause is that macOS runs a sleep late by a share of its length (timer coalescing). Measured on the Mac mini: | requested sleep | late by (p50 – p90) | |---|---| | 50 µs | 17–21 µs | | 1 ms | 256–267 µs | | 2 ms | 506–532 µs | | 14 ms (a 60 FPS frame's wait) | 1.75–3.5 ms | The limiter (vanilla's `FramerateLimiter`) learns an overshoot margin, but caps it at 2 ms and averages it. It can't cover 3.5 ms of variable lateness, so each frame wakes up after its deadline. `SystemClock::park` now sleeps at most 1 ms at a time until its deadline, so a frame can only be late by the last step's lateness. The limiter's logic is vanilla's and is not touched; both pacing modes (Precise and Efficient) use this clock. On Linux and Windows the steps change nothing they need: those sleeps were already precise. ## A/B in game 60 FPS cap, RD 16, offscreen, 3 alternated pairs (main / this PR) on the loaded Mac mini: | scenario | build | p50 | p99 | p99.9 | 1% low | 0.1% low | avg FPS | |---|---|---|---|---|---|---|---| | elytra | main | 17.28–17.37 | 19.76–19.93 | 19.94–20.04 | 50.1–50.3 | 48.1–50.2 | 56.8–57.6 | | elytra | PR | 16.70 | 16.75–16.76 | 16.85–18.13 | 58.4–59.6 | 53.1–59.1 | 59.9 | | fly64 | main | 16.89–17.33 | 19.61–19.86 | 19.89–19.94 | 50.3–50.6 | 49.8–50.3 | 57.5–57.7 | | fly64 | PR | 16.70 | 16.75–16.77 | 16.83–16.90 | 59.4–59.5 | 57.6–59.0 | 59.9 | I also ran a limiter alone in one process, alternating 6 rounds of each with 2 ms of work per frame, at 60 FPS on the same Mac (load ~29): | mode | frames late by more than 1 ms | p99 | |---|---|---| | Precise | 29.4 % → 2.0 % | 21.3 → 18.8 ms | | Efficient (default) | 32.5 % → 13.6 % | — | ## Test `a_frame_cap_holds_when_sleeps_run_late`: a clock whose sleeps run 25 % late, sleeping as `SystemClock::park` does, keeps a 60 FPS cap within 0.1 ms of 16.67 ms on every frame. With one long sleep, the first frame already lands 3.5 ms late. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at ae3cbb0f1, 4 min 14 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +68 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 6 s) | | rustfmt | ✅ (14 s) | | clippy | ✅ (1 min 46 s) | | tests: horizon-client-input | ✅ 68 passed (34 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | 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) | 🤖 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:22:20 +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#7707
No description provided.