[PR #3831] [MERGED] Streaming: the frame takes finished jobs without waiting for a worker #5239

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

📋 Pull Request Information

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

Base: main ← Head: perf/streaming-results-no-wait


📝 Commits (1)

  • 68e57e8 Streaming: the frame takes finished jobs without waiting for a worker

📊 Changes

1 file changed (+91 additions, -24 deletions)

View changed files

📝 crates/horizon-client-render/src/streaming.rs (+91 -24)

📄 Description

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

What and why

#3471's Windows benchmark (9800X3D + RTX 5080) has Horizon ahead of vanilla everywhere except the RD 32 ocean flight: 1% low 113 FPS vs vanilla's 228, with about 80 frames over 5 ms per flight (village: about 10), in all three repeats.

Reproduced on the Mac mini with HORIZON_SPIKES=4 (per-span wall and thread-CPU time): the long frames are the render thread waiting, not working. Each wait is 8–24 ms of wall time with ~0 ms of thread CPU, inside Streaming::update, in the loop that drains finished worker jobs. That loop used std's mpsc::Receiver::try_recv, which isn't wait-free. When it finds a sender half way through a send (slot reserved, message not written yet, or the next block not installed yet), it spins and then calls yield_now until that sender finishes (std sync/mpmc/list.rs: start_recv, Slot::wait_write). A worker descheduled at that point holds the frame for a scheduler quantum.

This hits hardest while flying fast at a large render distance: the most jobs and the busiest workers. Windows is the worst case. The client and the integrated server each run a pool of cores - 1 workers (15 + 15 on a 16-thread CPU), which aren't lowered in priority there, so workers get descheduled all the time.

The change: workers put finished jobs in a Mutex<VecDeque> (Mailbox), and the frame takes all of them with try_lock. While a worker holds the lock (a push), the frame leaves the results for the next frame instead of waiting. The blocking waits (save, wait, drop) keep their timeouts on a Condvar. Results keep their order, and nothing else changes.

Measured (Mac mini M4 Pro, tools/perf_bench.py --scenes ocean --offscreen, fast build)

The session was locked, so --offscreen. The machine was heavily loaded by other builds (load average 40–115), which is the condition that triggers these waits. Base and fix ran alternately so they share the load.

base (main 0a95d1c04) this PR
streaming waits > 3 ms in client frames, per RD 32 run (HORIZON_SPIKES) 5, 9, 14 (8–24 ms each) 0, 1 (4.9 ms)
RD 32 max frame, 4 flights 13.6, 21.1, 5.6, 8.1 ms 8.5, 7.1, 7.8, 9.0 ms
RD 32 frames ≥ 10 ms, 4 flights 5 0
RD 32 avg / 1% / 0.1% FPS (mean of 4) 354 / 182 / 132 350 / 182 / 141
RD 16 max frame, 2 flights 10.4, 12.2 ms 7.9, 3.5 ms
RD 16 avg / 1% / 0.1% FPS (mean of 2) 805 / 289 / 198 804 / 317 / 256

The Mac's 1% low is set by GPU time (p50 2.7 ms at RD 32), so the averages and 1% lows don't move beyond noise here. What changes is that the long stalls are gone. On the Windows machine (p50 0.8 ms) the same stalls are the 1% low. After this merges, d3grando's idle-machine rerun from #3471 will show how much of the 113 vs 228 it was. Other slow frames remain on the Mac (GPU waits in renderer, in-frame relight of fluid updates at 1–2 ms); they are next.

Vanilla reference

None: an internal threading change, no game behaviour.

Self-check

New unit test the_frame_takes_finished_jobs_without_waiting: the frame gets nothing (and doesn't block) while the lock is held, then gets both results in order; recv_timeout times out on an empty mailbox.

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at c7065027b, 7 min 7 s)

Check Result
Scope ✅ 1 files, +91 −24
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 423 passed (3 min 19 s)
rustfmt ✅ (27 s)
clippy ❌ failed (1 min 15 s)
tests: horizon-client-render ✅ 548 passed (19 s)
doc tests ✅ 0 passed (25 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 ➖ 108 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 96 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Rebased on main after #3698 (it frees stale meshes in the same receive loop; both kept). The block above is the rebased head 68e57e86c. Its clippy ❌ is not this PR: on macOS, gfx.rs's log_display (from #3461) is dead code, because its only caller is Linux-only, so -D warnings fails on plain main too. CI's verify (Linux) passes. Parity on the pre-rebase head 8151870ca: 109/109 affected harnesses pass locally (104 in the full pr_ready run, then world_reopen and world_spawn#1–#4 by name, 27 min).

🤖 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/3831 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/streaming-results-no-wait` --- ### 📝 Commits (1) - [`68e57e8`](https://github.com/horizon-rust/horizon/commit/68e57e86c58fa13128130fbe6b44f7ca2fab216b) Streaming: the frame takes finished jobs without waiting for a worker ### 📊 Changes **1 file changed** (+91 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/streaming.rs` (+91 -24) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why #3471's Windows benchmark (9800X3D + RTX 5080) has Horizon ahead of vanilla everywhere except the RD 32 ocean flight: 1% low 113 FPS vs vanilla's 228, with about 80 frames over 5 ms per flight (village: about 10), in all three repeats. Reproduced on the Mac mini with `HORIZON_SPIKES=4` (per-span wall and thread-CPU time): the long frames are the render thread **waiting**, not working. Each wait is 8–24 ms of wall time with ~0 ms of thread CPU, inside `Streaming::update`, in the loop that drains finished worker jobs. That loop used std's `mpsc::Receiver::try_recv`, which isn't wait-free. When it finds a sender half way through a send (slot reserved, message not written yet, or the next block not installed yet), it spins and then calls `yield_now` until that sender finishes (std `sync/mpmc/list.rs`: `start_recv`, `Slot::wait_write`). A worker descheduled at that point holds the frame for a scheduler quantum. This hits hardest while flying fast at a large render distance: the most jobs and the busiest workers. Windows is the worst case. The client and the integrated server each run a pool of `cores - 1` workers (15 + 15 on a 16-thread CPU), which aren't lowered in priority there, so workers get descheduled all the time. The change: workers put finished jobs in a `Mutex<VecDeque>` (`Mailbox`), and the frame takes all of them with `try_lock`. While a worker holds the lock (a push), the frame leaves the results for the next frame instead of waiting. The blocking waits (`save`, `wait`, drop) keep their timeouts on a `Condvar`. Results keep their order, and nothing else changes. ## Measured (Mac mini M4 Pro, `tools/perf_bench.py --scenes ocean --offscreen`, fast build) The session was locked, so `--offscreen`. The machine was heavily loaded by other builds (load average 40–115), which is the condition that triggers these waits. Base and fix ran alternately so they share the load. | | base (main 0a95d1c04) | this PR | |---|---|---| | `streaming` waits > 3 ms in client frames, per RD 32 run (HORIZON_SPIKES) | 5, 9, 14 (8–24 ms each) | 0, 1 (4.9 ms) | | RD 32 max frame, 4 flights | 13.6, 21.1, 5.6, 8.1 ms | 8.5, 7.1, 7.8, 9.0 ms | | RD 32 frames ≥ 10 ms, 4 flights | 5 | 0 | | RD 32 avg / 1% / 0.1% FPS (mean of 4) | 354 / 182 / 132 | 350 / 182 / 141 | | RD 16 max frame, 2 flights | 10.4, 12.2 ms | 7.9, 3.5 ms | | RD 16 avg / 1% / 0.1% FPS (mean of 2) | 805 / 289 / 198 | 804 / 317 / 256 | The Mac's 1% low is set by GPU time (p50 2.7 ms at RD 32), so the averages and 1% lows don't move beyond noise here. What changes is that the long stalls are gone. On the Windows machine (p50 0.8 ms) the same stalls are the 1% low. After this merges, d3grando's idle-machine rerun from #3471 will show how much of the 113 vs 228 it was. Other slow frames remain on the Mac (GPU waits in `renderer`, in-frame relight of fluid updates at 1–2 ms); they are next. ## Vanilla reference None: an internal threading change, no game behaviour. ## Self-check New unit test `the_frame_takes_finished_jobs_without_waiting`: the frame gets nothing (and doesn't block) while the lock is held, then gets both results in order; `recv_timeout` times out on an empty mailbox. **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at c7065027b, 7 min 7 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +91 −24 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 423 passed (3 min 19 s) | | rustfmt | ✅ (27 s) | | clippy | ❌ failed (1 min 15 s) | | tests: horizon-client-render | ✅ 548 passed (19 s) | | doc tests | ✅ 0 passed (25 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 | ➖ 108 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 96 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Rebased on main after #3698 (it frees stale meshes in the same receive loop; both kept). The block above is the rebased head 68e57e86c. Its clippy ❌ is not this PR: on macOS, `gfx.rs`'s `log_display` (from #3461) is dead code, because its only caller is Linux-only, so `-D warnings` fails on plain main too. CI's verify (Linux) passes. Parity on the pre-rebase head 8151870ca: 109/109 affected harnesses pass locally (104 in the full pr_ready run, then world_reopen and world_spawn#1–#4 by name, 27 min). 🤖 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:11:11 +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#5239
No description provided.