[PR #1179] [MERGED] Render thread ahead of the workers on macOS and Windows (RD 32 long frames) #3393

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

📋 Pull Request Information

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

Base: main ← Head: perf/render-thread-ahead


📝 Commits (1)

  • e70b520 Render thread ahead of the workers on macOS and Windows

📊 Changes

2 files changed (+12 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+7 -0)
📝 crates/horizon-threads/src/lib.rs (+5 -4)

📄 Description

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

Part of #678 (reported by rickdickem on Discord). No Fixes: the last PR of the set says what is left.

What

The client asks for its render thread what it already asks for the server thread (vanilla's MinecraftServer.spin, Thread.setPriority(8)): user-interactive QoS on macOS, above-normal priority on Windows, on machines with more than four processors (horizon_threads::favour_current, unchanged). Linux is not changed: an unprivileged thread can't raise itself there. See "What is left".

Why

taskinfo --threads on a running game (RD 32, server thread) showed:

  • the render thread at THREAD_QOS_LEGACY, base priority 31;
  • the server thread at USER_INTERACTIVE (37), above it;
  • 24 horizon-worker threads at 31, the same as the render thread. With single player's server thread there are two pools of N−2: the server's generation pool and the client's meshing pool. Vanilla shares one pool of N−1. There are also 13 horizon-chunk-encode threads.

While terrain loads, those threads and other programs outnumber the cores. The spans from #1178 show the result: frames over 12 ms in which the render thread worked less than a millisecond. It gave its core up in queue.submit and waited 10 to 200 ms to get one back (submit 33.3/0.1, encode 24.1/0.5, even hud 17.8/0.1).

With this change, taskinfo shows the render thread at USER_INTERACTIVE.

Before / after

Setup:

  • Mac mini, M4 Pro, 14 cores, Metal, --offscreen (the screen was locked).
  • Seed 1234, render distance 32, --server-thread, uncapped (maxFps 260, VSync off).
  • Raw frame times from horizon-ctl fly … raw.
  • Interleaved A/B runs, the same build except this change (main + #1178's spans in both).
  • The Mac mini was shared with other sessions: load average 18–114 during the runs (listed per table). Part of the gain is the render thread now beating other programs' threads, not only the game's own workers.

Fresh terrain: a new world each run, 30 s flight over 480 blocks while the world loads, 8 runs each:

p50 p99 p99.9 max frames > 16.7 ms per run avg FPS
before (per run) 1.47–14.86 ms 31.9–166.1 ms 88.7–207.1 ms 150–225 ms 311–611 36–310
after (per run) 0.30–0.71 ms 1.46–2.60 ms 3.41–5.64 ms 11.6–22.8 ms 0–2 1038–2338
before (pooled) 1.87 ms 81.4 ms 159.0 ms 224.7 ms
after (pooled) 0.47 ms 2.21 ms 4.47 ms 22.8 ms

Load average: 22–90 before, 35–114 after.

Loaded terrain: one world per run, wait until no chunk is pending, then fly the village path back and forth (4 × 12 s), 2 runs each:

p50 p99 p99.9 max frames > 16.7 ms
before 2.17–2.40 ms 14.4–17.5 ms 38.5–39.2 ms 85–115 ms 147–204
after 1.26–1.33 ms 3.22–3.32 ms 7.03–7.85 ms 13–38 ms 0–1

Load average: 22–48.

World in the frame (no --server-thread, today's default until #1114), fresh terrain, 2 runs each:

p50 p99 p99.9 max
before 1.92–2.94 ms 33.2–64.2 ms 72.6–107.2 ms 128–138 ms
after 1.74–1.78 ms 6.63–6.75 ms 8.11–8.23 ms 11.8–12.0 ms

Chunk loading is not slower. Columns loaded at the end of the 30 s flight: 3566 and 3707 before, 3696 and 3715 after (3725 for all four, 10 s later).

Screenshot comparison

A thread hint changes no pixel. I took offscreen screenshots at the same spot (seed 1234, RD 12):

  • this branch against main: 209k pixels differ;
  • main against main: 299k pixels differ (time of day and animated textures).

The difference is within the run-to-run noise.

How tested (Mac mini M4 Pro)

  • cargo fmt --all --check: ok
  • set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-threads: 2 passed. cargo test -p horizon-client: all passed (985 lib, 91 bin, …).
  • tools/parity.py --changed origin/main, on one integration commit with #1178: 102 passed, 0 failed.

What is left (in FEATURES.md LATER)

  • Linux: the render thread can't be raised. The matching fix is the client's workers going behind it (horizon_threads::behind_server, already used by the dedicated server). It needs a measurement on the desktop, which this agent could not use.
  • The two worker pools of N−2 with the server thread (vanilla: one shared pool of N−1).

Needs Ludovic

Nothing, unless he wants the Linux half measured on the desktop.

🤖 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/1179 **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/render-thread-ahead` --- ### 📝 Commits (1) - [`e70b520`](https://github.com/horizon-rust/horizon/commit/e70b520e5d92f0f1a755413404b875c7c2476c44) Render thread ahead of the workers on macOS and Windows ### 📊 Changes **2 files changed** (+12 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+7 -0) 📝 `crates/horizon-threads/src/lib.rs` (+5 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of #678 (reported by **rickdickem** on Discord). No `Fixes`: the last PR of the set says what is left. ## What The client asks for its render thread what it already asks for the server thread (vanilla's `MinecraftServer.spin`, `Thread.setPriority(8)`): user-interactive QoS on macOS, above-normal priority on Windows, on machines with more than four processors (`horizon_threads::favour_current`, unchanged). Linux is not changed: an unprivileged thread can't raise itself there. See "What is left". ## Why `taskinfo --threads` on a running game (RD 32, server thread) showed: - the render thread at `THREAD_QOS_LEGACY`, base priority 31; - the server thread at `USER_INTERACTIVE` (37), above it; - 24 `horizon-worker` threads at 31, the same as the render thread. With single player's server thread there are two pools of N−2: the server's generation pool and the client's meshing pool. Vanilla shares one pool of N−1. There are also 13 `horizon-chunk-encode` threads. While terrain loads, those threads and other programs outnumber the cores. The spans from #1178 show the result: frames over 12 ms in which the render thread worked less than a millisecond. It gave its core up in `queue.submit` and waited 10 to 200 ms to get one back (`submit 33.3/0.1`, `encode 24.1/0.5`, even `hud 17.8/0.1`). With this change, `taskinfo` shows the render thread at `USER_INTERACTIVE`. ## Before / after Setup: - Mac mini, M4 Pro, 14 cores, Metal, `--offscreen` (the screen was locked). - Seed 1234, render distance 32, `--server-thread`, uncapped (maxFps 260, VSync off). - Raw frame times from `horizon-ctl fly … raw`. - Interleaved A/B runs, the same build except this change (`main` + #1178's spans in both). - The Mac mini was shared with other sessions: load average 18–114 during the runs (listed per table). Part of the gain is the render thread now beating other programs' threads, not only the game's own workers. **Fresh terrain**: a new world each run, 30 s flight over 480 blocks while the world loads, 8 runs each: | | p50 | p99 | p99.9 | max | frames > 16.7 ms per run | avg FPS | |---|---|---|---|---|---|---| | before (per run) | 1.47–14.86 ms | 31.9–166.1 ms | 88.7–207.1 ms | 150–225 ms | 311–611 | 36–310 | | after (per run) | 0.30–0.71 ms | 1.46–2.60 ms | 3.41–5.64 ms | 11.6–22.8 ms | 0–2 | 1038–2338 | | before (pooled) | 1.87 ms | 81.4 ms | 159.0 ms | 224.7 ms | | | | after (pooled) | 0.47 ms | 2.21 ms | 4.47 ms | 22.8 ms | | | Load average: 22–90 before, 35–114 after. **Loaded terrain**: one world per run, wait until no chunk is pending, then fly the village path back and forth (4 × 12 s), 2 runs each: | | p50 | p99 | p99.9 | max | frames > 16.7 ms | |---|---|---|---|---|---| | before | 2.17–2.40 ms | 14.4–17.5 ms | 38.5–39.2 ms | 85–115 ms | 147–204 | | after | 1.26–1.33 ms | 3.22–3.32 ms | 7.03–7.85 ms | 13–38 ms | 0–1 | Load average: 22–48. **World in the frame** (no `--server-thread`, today's default until #1114), fresh terrain, 2 runs each: | | p50 | p99 | p99.9 | max | |---|---|---|---|---| | before | 1.92–2.94 ms | 33.2–64.2 ms | 72.6–107.2 ms | 128–138 ms | | after | 1.74–1.78 ms | 6.63–6.75 ms | 8.11–8.23 ms | 11.8–12.0 ms | Chunk loading is not slower. Columns loaded at the end of the 30 s flight: 3566 and 3707 before, 3696 and 3715 after (3725 for all four, 10 s later). ## Screenshot comparison A thread hint changes no pixel. I took offscreen screenshots at the same spot (seed 1234, RD 12): - this branch against `main`: 209k pixels differ; - `main` against `main`: 299k pixels differ (time of day and animated textures). The difference is within the run-to-run noise. ## How tested (Mac mini M4 Pro) - `cargo fmt --all --check`: ok - `set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-threads`: 2 passed. `cargo test -p horizon-client`: all passed (985 lib, 91 bin, …). - `tools/parity.py --changed origin/main`, on one integration commit with #1178: **102 passed, 0 failed**. ## What is left (in FEATURES.md LATER) - Linux: the render thread can't be raised. The matching fix is the client's workers going behind it (`horizon_threads::behind_server`, already used by the dedicated server). It needs a measurement on the desktop, which this agent could not use. - The two worker pools of N−2 with the server thread (vanilla: one shared pool of N−1). ## Needs Ludovic Nothing, unless he wants the Linux half measured on the desktop. 🤖 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:12 +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#3393
No description provided.