[PR #1192] [MERGED] Linux: the game's workers go behind its render and server threads (RD 32 long frames) #3406

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

📋 Pull Request Information

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

Base: main ← Head: perf/linux-helpers-behind


📝 Commits (3)

  • 7708099 Render thread ahead of the workers on macOS and Windows
  • 41a4ce4 Linux: the game's workers go behind its render and server threads
  • c4a1296 Merge origin/main into perf/linux-helpers-behind (game.rs: helpers behind on every run, plus main's live-count ping)

📊 Changes

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

View changed files

📝 crates/horizon-client/src/game.rs (+4 -4)
📝 crates/horizon-client/src/lan/conn.rs (+1 -1)
📝 crates/horizon-client/src/streaming.rs (+1 -1)
📝 crates/horizon-threads/src/lib.rs (+14 -14)

📄 Description

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

Part of #678 (reported by rickdickem on Discord). This is the Linux half of #1179, FEATURES 4r(a).

Stacked on #1181 and #1179: the branch carries their commits, and GitHub drops them once they merge. This PR's own diff is the last commit (41a4ce4e, 4 files, about 20 lines).

What

On Linux an unprivileged thread can't raise itself, so #1179's render-thread hint does nothing there. The dedicated server already lowered its helper threads instead: 10 nice levels, or the idle class when nice runs out (horizon_threads::behind_server). The client now does the same (put_helpers_behind for every game, not only --dedicated). That covers:

  • the world-generation and meshing workers, two pools of N−2 with single player's server thread;
  • the region worker and the LAN connection writers.

The render thread, the server thread and the chunk encoders stay at the process's level. On macOS and Windows nothing changes: behind() is Linux-only.

Proof from the running game (desktop, ps -L): 44 horizon-worker threads, horizon-region and horizon-lan-out at nice 10; the render thread, Server thread and the 23 horizon-chunk-encode threads at 0.

Before / after (desktop, Linux, Vulkan)

Setup:

  • Ryzen with 24 threads, RTX 4080, --offscreen on vscreen.
  • Seed 1234, render distance 32, --server-thread, uncapped.
  • Raw frame times from horizon-ctl fly … raw.
  • Interleaved A/B runs. Both builds are #1181 + #1179 (+ #1178's spans); only this commit differs.

The desktop was shared with 3–4 other agents (an integration parity run, perf-server-13, LAN harnesses) and never got quiet. The load average during each set is listed.

Fresh terrain (a new world each run, 30 s over 480 blocks while it loads), the case where the game's own workers are busy:

Set Runs p50 p99 p99.9 max frames > 16.7 ms per flight
Moderate load (16–24), before 5 0.67–0.77 ms 5.07–9.55 ms 16.0–32.2 ms 50–118 ms 29–94
Moderate load, after 5 0.52–0.69 ms 3.21–5.41 ms 6.79–13.1 ms 17–46 ms 1–10
Moderate load, pooled 0.71 → 0.63 ms 6.87 → 4.14 ms 22.2 → 9.8 ms 118 → 46 ms
Heavy load (34–80), before 3 0.54–2.27 ms 36.2–70.0 ms 128–218 ms 294–409 ms 269–460
Heavy load, after 3 0.66–1.27 ms 4.94–17.1 ms 10.8–44.6 ms 20–164 ms 6–152

Chunk loading is not slower. Columns loaded at the end of the flight:

  • before: 3699, 3661, 3045, 3715, 3714;
  • after: 3714, 3669, 3623, 3716, 3715.

All runs had 3725 columns 10 s later. Under heavy load, the starved render thread had even held meshing back.

Loaded terrain (back and forth, 4 × 12 s), 2 pairs at load 30–114: within noise (pooled p99.9 27.6 → 26.0 ms). The workers are mostly idle there, and the long frames came from other programs.

What is left on Linux

With this change, about half of the remaining frames over 8 ms (fresh terrain, load ~27) did less than half their wall time in CPU. That is preemption by the other agents' builds and harnesses, which an unprivileged game can't outrank. A player's idle machine doesn't have it, but I could not measure an idle desktop.

The other half are real work: mesh uploads (upload 5–10 ms), and an occasional 5 ms flush of chunk packets that waited 50 ms (#1181's backlog limit). These are in FEATURES 4r.

How tested

On the Mac mini (the desktop stayed free for measuring):

  • cargo fmt --all --check: ok
  • set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-threads -p horizon-client: all passed.
  • tools/parity.py --changed origin/main: 101 passed, 1 failed. The failure is dedicated_server with play-pearl teleported 0 time(s), the known flake on main (FEATURES "dedicated_server harness flakes"). The behind path is Linux-only, so the Mac result can't come from this change. tools/parity.py dedicated_server then passed.

On the desktop (Linux):

  • cargo test -p horizon-threads: 2 passed, including helpers_go_behind_only_when_asked, which checks the nice levels.
  • tools/lan_e2e.py --server-thread --check tab chest chat mobs damage: all passed (LAN writers and both pools at nice 10).

No rendering change.

🤖 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/1192 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/linux-helpers-behind` --- ### 📝 Commits (3) - [`7708099`](https://github.com/horizon-rust/horizon/commit/770809908dc627c1a5409eb14252d4069e588c8b) Render thread ahead of the workers on macOS and Windows - [`41a4ce4`](https://github.com/horizon-rust/horizon/commit/41a4ce4edb15aa2abdaa902d847e7322d15e0e44) Linux: the game's workers go behind its render and server threads - [`c4a1296`](https://github.com/horizon-rust/horizon/commit/c4a12964dca8a03c6cc1df8576bd1f72aa67a934) Merge origin/main into perf/linux-helpers-behind (game.rs: helpers behind on every run, plus main's live-count ping) ### 📊 Changes **4 files changed** (+20 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+4 -4) 📝 `crates/horizon-client/src/lan/conn.rs` (+1 -1) 📝 `crates/horizon-client/src/streaming.rs` (+1 -1) 📝 `crates/horizon-threads/src/lib.rs` (+14 -14) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of #678 (reported by **rickdickem** on Discord). This is the Linux half of #1179, FEATURES 4r(a). **Stacked on #1181 and #1179**: the branch carries their commits, and GitHub drops them once they merge. This PR's own diff is the last commit (`41a4ce4e`, 4 files, about 20 lines). ## What On Linux an unprivileged thread can't raise itself, so #1179's render-thread hint does nothing there. The dedicated server already lowered its helper threads instead: 10 nice levels, or the idle class when nice runs out (`horizon_threads::behind_server`). The client now does the same (`put_helpers_behind` for every game, not only `--dedicated`). That covers: - the world-generation and meshing workers, two pools of N−2 with single player's server thread; - the region worker and the LAN connection writers. The render thread, the server thread and the chunk encoders stay at the process's level. On macOS and Windows nothing changes: `behind()` is Linux-only. Proof from the running game (desktop, `ps -L`): 44 `horizon-worker` threads, `horizon-region` and `horizon-lan-out` at nice 10; the render thread, `Server thread` and the 23 `horizon-chunk-encode` threads at 0. ## Before / after (desktop, Linux, Vulkan) Setup: - Ryzen with 24 threads, RTX 4080, `--offscreen` on vscreen. - Seed 1234, render distance 32, `--server-thread`, uncapped. - Raw frame times from `horizon-ctl fly … raw`. - Interleaved A/B runs. Both builds are #1181 + #1179 (+ #1178's spans); only this commit differs. The desktop was shared with 3–4 other agents (an integration parity run, perf-server-13, LAN harnesses) and never got quiet. The load average during each set is listed. **Fresh terrain** (a new world each run, 30 s over 480 blocks while it loads), the case where the game's own workers are busy: | Set | Runs | p50 | p99 | p99.9 | max | frames > 16.7 ms per flight | |---|---|---|---|---|---|---| | Moderate load (16–24), before | 5 | 0.67–0.77 ms | 5.07–9.55 ms | 16.0–32.2 ms | 50–118 ms | 29–94 | | Moderate load, after | 5 | 0.52–0.69 ms | 3.21–5.41 ms | **6.79–13.1 ms** | 17–46 ms | 1–10 | | Moderate load, pooled | | 0.71 → 0.63 ms | 6.87 → 4.14 ms | 22.2 → 9.8 ms | 118 → 46 ms | | | Heavy load (34–80), before | 3 | 0.54–2.27 ms | 36.2–70.0 ms | 128–218 ms | 294–409 ms | 269–460 | | Heavy load, after | 3 | 0.66–1.27 ms | 4.94–17.1 ms | **10.8–44.6 ms** | 20–164 ms | 6–152 | Chunk loading is not slower. Columns loaded at the end of the flight: - before: 3699, 3661, 3045, 3715, 3714; - after: 3714, 3669, 3623, 3716, 3715. All runs had 3725 columns 10 s later. Under heavy load, the starved render thread had even held meshing back. **Loaded terrain** (back and forth, 4 × 12 s), 2 pairs at load 30–114: within noise (pooled p99.9 27.6 → 26.0 ms). The workers are mostly idle there, and the long frames came from other programs. ## What is left on Linux With this change, about half of the remaining frames over 8 ms (fresh terrain, load ~27) did less than half their wall time in CPU. That is preemption by the other agents' builds and harnesses, which an unprivileged game can't outrank. A player's idle machine doesn't have it, but I could not measure an idle desktop. The other half are real work: mesh uploads (`upload` 5–10 ms), and an occasional 5 ms flush of chunk packets that waited 50 ms (#1181's backlog limit). These are in FEATURES 4r. ## How tested On the Mac mini (the desktop stayed free for measuring): - `cargo fmt --all --check`: ok - `set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-threads -p horizon-client`: all passed. - `tools/parity.py --changed origin/main`: **101 passed, 1 failed**. The failure is `dedicated_server` with `play-pearl teleported 0 time(s)`, the known flake on main (FEATURES "dedicated_server harness flakes"). The behind path is Linux-only, so the Mac result can't come from this change. `tools/parity.py dedicated_server` then passed. On the desktop (Linux): - `cargo test -p horizon-threads`: 2 passed, including `helpers_go_behind_only_when_asked`, which checks the nice levels. - `tools/lan_e2e.py --server-thread --check tab chest chat mobs damage`: all passed (LAN writers and both pools at nice 10). No rendering change. 🤖 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 04:09:18 +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#3406
No description provided.