[PR #6721] [MERGED] Streaming: run on the shared worker pool #7054

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

📋 Pull Request Information

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

Base: main ← Head: perf-jobs/streaming


📝 Commits (1)

  • d5be28d Streaming: run on the shared worker pool

📊 Changes

7 files changed (+204 additions, -212 deletions)

View changed files

📝 crates/horizon-client-render/src/crash.rs (+2 -1)
📝 crates/horizon-client-render/src/streaming.rs (+190 -202)
📝 crates/horizon-client/examples/chunk_load_bench.rs (+3 -2)
📝 crates/horizon-client/src/game.rs (+5 -3)
📝 crates/horizon-client/tests/generation_saves.rs (+1 -1)
📝 crates/horizon-client/tests/streaming_meshes.rs (+2 -2)
📝 crates/horizon-client/tests/tall_column.rs (+1 -1)

📄 Description

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

Stacked on #6719 (the shared pool). Every chunk streamer (the window's, and one per level on the single-player server thread) started N-1 worker threads of its own. They now queue their jobs on the process's one pool (horizon_threads::jobs), which the game sizes from the workers setting before any world opens.

  • Streaming keeps its queue, priorities (submit, requeue/rank_again) and its API. Its queue is a Source: saves and freed meshes are Urgent, everything else Near with the existing key (column distance × 4 + stage bias). So server generation and client meshing now interleave by distance instead of two full pools racing.
  • Per-worker state (the generator's worker, the face visibility cache, the mesh scratch) moves into the streamer's PerWorker slots. Idle release keeps the old behaviour: generator idle after 5 s, the mesh pool and release_free_memory once all workers are idle.
  • Drop waits for in-flight saves as before. Dropping the registration then waits for the streamer's running jobs (this was the thread join).
  • Streaming::new(.., threads) now sizes the work it keeps in flight (min(threads, pool)), not a thread count. chunk_load_bench --threads N sizes the pool.
  • Tests: the streaming integration tests' "settled" check used pending() == 0 (queued jobs only). With more workers, a long light job of the 2096-block column could still be running when the queue was empty, and tall_column failed 2 of 3 runs on 13 workers (3 of 3 passed with HORIZON_JOB_THREADS=2). The check is now !busy() (queued or in flight): 4/4 and 2/2 on 13 workers.
  • Determinism: jobs do the same work on the same inputs, and only which thread runs them changes (already arbitrary). Decoration order and sequence numbers are untouched.

Measured

Mac mini M4 Pro (14 threads), perf_bench --distances 32 --scenes village,forest --sizes 1600x900 --offscreen, server thread (default), main db34ce484d vs this stack (this PR + #6722, final pool core), alternated A/B, n=6 (two rounds), load 17-54 from other agents' builds and CI (loaded). Medians:

metric main this stack
threads at peak 62.5 38 −39%
context switches /s 22 464 20 441 −9%
world entry (ms) 18 179 15 512 −15%
village chunk load (ms) 8 288 6 168 −26%
forest chunk load (ms) 12 193 8 990 −26%
section meshes during the two loads 50 345 / 84 488 47 470 / 79 589 −6% (fewer remeshes)
village flight p99 / p99.9 (ms) 3.77 / 4.93 3.82 / 4.68 = (GPU-bound)
forest flight p99 / p99.9 (ms) 6.56 / 7.57 6.53 / 7.33 = (GPU-bound)

The pairs are noisy (one loaded run of each variant took 20-33 s): chunk loads were faster in 4 of 6 pairs for each scene. An earlier version of the pool made the render thread's submit take the pool lock (see #6719). Flight p99 in the village was then 0.2-0.3 ms worse in most pairs; with the final core it is level.

Linux VPS (playhorizon, 8 vCPU), 4-thread budget: taskset -c 0-3 (available_parallelism = 4), lavapipe 320x180 offscreen, RD 32 village, main 51946c9e4 vs this stack, alternated, n=3. Those 4 CPUs are shared with other agents' builds (load 24-36), so everything is preempted constantly. The frame rate (1.5 fps in software rendering) says nothing here; per-thread numbers come from /proc.

metric main this stack
compute threads started (workers + encode) 14 3
threads at peak 30 24
world entry (ms) 150 745 142 252 3/3 pairs faster, −6%
village chunk load (ms) 151 346 142 347 2/3 pairs faster
worker CPU (s) 164 161 same work
context switches /s (involuntary) 2 050 (1 247) 2 486 (1 476) higher: under load 30 on 4 CPUs, preemption by other processes dominates

Not measured: an idle machine at any size (none available: the Mac runs other agents' builds and CI, the VPS's 4 CPUs are the build slots). There was no 8- or 32-thread budget either: the VPS's CPUs 4-7 are its CI runner's, and no 32-thread machine is available. Under contention, a pool of N-1 threads also gets a smaller share of the machine than the old 2-3 × (N-1) did, which the loaded runs show as noise in both directions. The expected win is largest exactly where it couldn't be measured: idle many-core Windows (14 → 3 on 4 threads here, ~94 → 31 on 32 threads).

pr_ready (the whole stack, #6719 + this + #6722)

pr_ready (tools/pr_ready.py --quick --base db34ce484d on ludovics-mac-mini, against db34ce484d at db34ce484, 10 min 11 s)

Check Result
Scope ⚠️ 10 files, +945 −258; 1195 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 596 passed (3 min 12 s)
rustfmt ✅ (13 s)
clippy ✅ (1 min 25 s)
tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-threads ✅ 2932 passed (4 min 58 s)
doc tests ✅ 0 passed (4 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)

Parity: 132 affected harnesses, run by CI.

🤖 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/6721 **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-jobs/streaming` --- ### 📝 Commits (1) - [`d5be28d`](https://github.com/horizon-rust/horizon/commit/d5be28d945ec408fe2e9cfac0f0bcba28ad21fdd) Streaming: run on the shared worker pool ### 📊 Changes **7 files changed** (+204 additions, -212 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/crash.rs` (+2 -1) 📝 `crates/horizon-client-render/src/streaming.rs` (+190 -202) 📝 `crates/horizon-client/examples/chunk_load_bench.rs` (+3 -2) 📝 `crates/horizon-client/src/game.rs` (+5 -3) 📝 `crates/horizon-client/tests/generation_saves.rs` (+1 -1) 📝 `crates/horizon-client/tests/streaming_meshes.rs` (+2 -2) 📝 `crates/horizon-client/tests/tall_column.rs` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #6719 (the shared pool). Every chunk streamer (the window's, and one per level on the single-player server thread) started N-1 worker threads of its own. They now queue their jobs on the process's one pool (`horizon_threads::jobs`), which the game sizes from the `workers` setting before any world opens. - `Streaming` keeps its queue, priorities (`submit`, `requeue`/`rank_again`) and its API. Its queue is a `Source`: saves and freed meshes are `Urgent`, everything else `Near` with the existing key (column distance × 4 + stage bias). So server generation and client meshing now interleave by distance instead of two full pools racing. - Per-worker state (the generator's worker, the face visibility cache, the mesh scratch) moves into the streamer's `PerWorker` slots. Idle release keeps the old behaviour: generator `idle` after 5 s, the mesh pool and `release_free_memory` once all workers are idle. - `Drop` waits for in-flight saves as before. Dropping the registration then waits for the streamer's running jobs (this was the thread join). - `Streaming::new(.., threads)` now sizes the work it keeps in flight (`min(threads, pool)`), not a thread count. `chunk_load_bench --threads N` sizes the pool. - Tests: the streaming integration tests' "settled" check used `pending() == 0` (queued jobs only). With more workers, a long light job of the 2096-block column could still be running when the queue was empty, and `tall_column` failed 2 of 3 runs on 13 workers (3 of 3 passed with `HORIZON_JOB_THREADS=2`). The check is now `!busy()` (queued or in flight): 4/4 and 2/2 on 13 workers. - Determinism: jobs do the same work on the same inputs, and only which thread runs them changes (already arbitrary). Decoration order and sequence numbers are untouched. ## Measured Mac mini M4 Pro (14 threads), `perf_bench --distances 32 --scenes village,forest --sizes 1600x900 --offscreen`, server thread (default), main `db34ce484d` vs this stack (this PR + #6722, final pool core), alternated A/B, n=6 (two rounds), **load 17-54 from other agents' builds and CI** (loaded). Medians: | metric | main | this stack | | |---|---|---|---| | threads at peak | 62.5 | **38** | −39% | | context switches /s | 22 464 | 20 441 | −9% | | world entry (ms) | 18 179 | 15 512 | −15% | | village chunk load (ms) | 8 288 | 6 168 | −26% | | forest chunk load (ms) | 12 193 | 8 990 | −26% | | section meshes during the two loads | 50 345 / 84 488 | 47 470 / 79 589 | −6% (fewer remeshes) | | village flight p99 / p99.9 (ms) | 3.77 / 4.93 | 3.82 / 4.68 | = (GPU-bound) | | forest flight p99 / p99.9 (ms) | 6.56 / 7.57 | 6.53 / 7.33 | = (GPU-bound) | The pairs are noisy (one loaded run of each variant took 20-33 s): chunk loads were faster in 4 of 6 pairs for each scene. An earlier version of the pool made the render thread's `submit` take the pool lock (see #6719). Flight p99 in the village was then 0.2-0.3 ms worse in most pairs; with the final core it is level. Linux VPS (playhorizon, 8 vCPU), **4-thread budget**: `taskset -c 0-3` (`available_parallelism` = 4), lavapipe 320x180 offscreen, RD 32 village, main `51946c9e4` vs this stack, alternated, n=3. Those 4 CPUs are shared with other agents' builds (**load 24-36**), so everything is preempted constantly. The frame rate (1.5 fps in software rendering) says nothing here; per-thread numbers come from `/proc`. | metric | main | this stack | | |---|---|---|---| | compute threads started (workers + encode) | 14 | **3** | | | threads at peak | 30 | 24 | | | world entry (ms) | 150 745 | 142 252 | 3/3 pairs faster, −6% | | village chunk load (ms) | 151 346 | 142 347 | 2/3 pairs faster | | worker CPU (s) | 164 | 161 | same work | | context switches /s (involuntary) | 2 050 (1 247) | 2 486 (1 476) | higher: under load 30 on 4 CPUs, preemption by other processes dominates | Not measured: an idle machine at any size (none available: the Mac runs other agents' builds and CI, the VPS's 4 CPUs are the build slots). There was no 8- or 32-thread budget either: the VPS's CPUs 4-7 are its CI runner's, and no 32-thread machine is available. Under contention, a pool of N-1 threads also gets a smaller share of the machine than the old 2-3 × (N-1) did, which the loaded runs show as noise in both directions. The expected win is largest exactly where it couldn't be measured: idle many-core Windows (14 → 3 on 4 threads here, ~94 → 31 on 32 threads). ## pr_ready (the whole stack, #6719 + this + #6722) **pr_ready** (`tools/pr_ready.py --quick --base db34ce484d` on ludovics-mac-mini, against db34ce484d at db34ce484, 10 min 11 s) | Check | Result | | --- | --- | | Scope | ⚠️ 10 files, +945 −258; 1195 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 596 passed (3 min 12 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (1 min 25 s) | | tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-threads | ✅ 2932 passed (4 min 58 s) | | doc tests | ✅ 0 passed (4 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) | Parity: 132 affected harnesses, run by CI. 🤖 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:57 +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#7054
No description provided.