[PR #6698] [MERGED] Linux: the submit thread's queue waits count as waiting, not as frame CPU #7040

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

📋 Pull Request Information

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

Base: main ← Head: perf/submit-wait-is-wait


📝 Commits (2)

  • 1fad808 Frame stats: waits for the submit thread count as waiting, not CPU
  • 08508f5 rustfmt

📊 Changes

2 files changed (+32 additions, -3 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+17 -2)
📝 crates/horizon-client-render/src/gfx/submit.rs (+15 -1)

📄 Description

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

What and why

On Linux, frames go to a submit thread (gfx/submit.rs, #5779). Each use of the queue on the render thread (Queue's Deref) first waits for that thread to finish submitting and presenting the previous frame. Those waits are blocked time, but they were missing from Renderer::last_wait, so they got counted as the frame's CPU time. That CPU time (wall minus last_wait) feeds:

  • the CPU line of the frame graph;
  • the GPU utilisation figure;
  • FrameStats::record_cpu (perf_bench's cpu_p50_ms, the benchmark reports);
  • the HORIZON_SPIKES threshold and its slow frame N ms lines.

On a machine where the GPU is the slow part, the frame's "CPU" showed the GPU's time, and HORIZON_SPIKES logged GPU-bound frames as CPU hitches.

The change: Queue::wait times each blocking receive and adds it to an AtomicU64, and take_waited reads and resets it. draw_frame adds what was waited before the surface is acquired, through the frame, and before present to last_wait. Waits after the frame's own present belong to the next frame, so they are dropped. Nothing changes in what is drawn or when.

Measured

What the old accounting reported, from a frame-pacing run on main: playhorizon, lavapipe at 320x180 (GPU-bound), tools/pacing_bench.py --distances 12 --spike-ms 8, five scenarios. HORIZON_SPIKES logs, for each frame, the counted CPU time and the render thread's own CPU time (thread_cpu):

frames logged slow (counted CPU > 8 ms) main
all 6,013
counted ≥ 33 ms, thread CPU under a quarter of that 2,434 (40%)
worst of those 4,806 ms counted, 3.4 ms thread CPU (r_uploads_flatten 4,803 ms wall, 0.0 ms CPU: the queue wait)

With this change, those frames count only the render thread's work. The A/B of the same run comes with the frame-pacing series (tools/pacing_bench.py, PR to follow), and is added here when it lands.

The submit thread is on by default only on Linux (HORIZON_SUBMIT_THREAD), so macOS and Windows figures don't change.

Checks

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 4bc8e359c, 9 min 12 s)

Check Result
Scope ✅ 2 files, +32 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 598 passed (4 min 21 s)
rustfmt ✅ (8 s)
clippy ✅ (2 min 32 s)
tests: horizon-client-render ✅ 988 passed (1 min 29 s)
doc tests ✅ 0 passed (1 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 ➖ 132 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 120 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/6698 **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/submit-wait-is-wait` --- ### 📝 Commits (2) - [`1fad808`](https://github.com/horizon-rust/horizon/commit/1fad808164cfbf45a766acb612c4ca76bf460cec) Frame stats: waits for the submit thread count as waiting, not CPU - [`08508f5`](https://github.com/horizon-rust/horizon/commit/08508f5d8668dcb0bccd1efb66ac589d6511d778) rustfmt ### 📊 Changes **2 files changed** (+32 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+17 -2) 📝 `crates/horizon-client-render/src/gfx/submit.rs` (+15 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why On Linux, frames go to a submit thread (`gfx/submit.rs`, #5779). Each use of the queue on the render thread (`Queue`'s `Deref`) first waits for that thread to finish submitting and presenting the previous frame. Those waits are blocked time, but they were missing from `Renderer::last_wait`, so they got counted as the frame's CPU time. That CPU time (wall minus `last_wait`) feeds: - the CPU line of the frame graph; - the GPU utilisation figure; - `FrameStats::record_cpu` (perf_bench's `cpu_p50_ms`, the benchmark reports); - the `HORIZON_SPIKES` threshold and its `slow frame N ms` lines. On a machine where the GPU is the slow part, the frame's "CPU" showed the GPU's time, and `HORIZON_SPIKES` logged GPU-bound frames as CPU hitches. The change: `Queue::wait` times each blocking receive and adds it to an `AtomicU64`, and `take_waited` reads and resets it. `draw_frame` adds what was waited before the surface is acquired, through the frame, and before present to `last_wait`. Waits after the frame's own present belong to the next frame, so they are dropped. Nothing changes in what is drawn or when. ## Measured What the old accounting reported, from a frame-pacing run on main: playhorizon, lavapipe at 320x180 (GPU-bound), `tools/pacing_bench.py --distances 12 --spike-ms 8`, five scenarios. `HORIZON_SPIKES` logs, for each frame, the counted CPU time and the render thread's own CPU time (`thread_cpu`): | frames logged slow (counted CPU > 8 ms) | main | |---|---| | all | 6,013 | | counted ≥ 33 ms, thread CPU under a quarter of that | 2,434 (40%) | | worst of those | 4,806 ms counted, 3.4 ms thread CPU (`r_uploads_flatten` 4,803 ms wall, 0.0 ms CPU: the queue wait) | With this change, those frames count only the render thread's work. The A/B of the same run comes with the frame-pacing series (`tools/pacing_bench.py`, PR to follow), and is added here when it lands. The submit thread is on by default only on Linux (`HORIZON_SUBMIT_THREAD`), so macOS and Windows figures don't change. ## Checks **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 4bc8e359c, 9 min 12 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +32 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 598 passed (4 min 21 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (2 min 32 s) | | tests: horizon-client-render | ✅ 988 passed (1 min 29 s) | | doc tests | ✅ 0 passed (1 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 | ➖ 132 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 120 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:32:35 +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#7040
No description provided.