[PR #2480] [MERGED] Streaming: rank queued chunk jobs again when the centre or the loading screen changes #4355

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

📋 Pull Request Information

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

Base: main ← Head: perf/requeue-on-centre-change


📝 Commits (1)

  • 8920f08 Streaming: rank queued jobs again when the centre or the loading screen changes

📊 Changes

1 file changed (+113 additions, -9 deletions)

View changed files

📝 crates/horizon-client/src/streaming.rs (+113 -9)

📄 Description

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

Part of the roadmap item world-entry (faster world creation and entry).

What and why

Chunk jobs (generate, decorate, light, mesh) wait in a priority queue, nearest first. Each job's priority was fixed when it was queued, from the centre and mode of that moment. Two things broke the order:

  • The loading screen. While it is up, jobs are ranked ring by ring (Ranges::rings: ring² << 20 | d²). Once it closes they are ranked by plain distance (d², below 2²⁰). A job queued during the loading screen therefore waited behind every job queued after it, however far away those were.
  • The centre moving (spawn search, the player arriving, a teleport): jobs queued for the old centre kept their old order.

The jobs stranded this way included proto chunks next to the spawn. Decoration follows vanilla's order (DecorationOrder), so one missing proto near the player held back every decoration around it. In-frame at render distance 32 on the Mac mini, the world stayed at 15 to 47 chunks for 10 to 13 seconds while the workers generated all ~3,900 proto chunks of the area. Only then did the first decoration run. Instrumented run: the lowest-ranked chunk (−37, 8) waited on proto (−37, −1), which was "generating" (queued) from 2 s until every other proto was done.

Now each queued job keeps its column and its bias (the existing * 4 + 0/1/2 per job kind). When the centre, the extra areas, the band or the loading-screen flag change, Streaming::requeue computes the priorities again and rebuilds the heap. That is O(queued jobs), once per change. Vanilla's chunk task queue follows the current ticket levels in the same way.

Decoration order is unaffected: it is still enforced by DecorationOrder::blocked, which never lets two overlapping decorations run at once. Only the order of independent jobs in the worker queue changes.

Measured

entry_bench (scratch driver on top of perf_bench's control socket): it times open PerfBench 1234 creative from the title screen to the first resident chunk, the first meshed section, and "all": every chunk of the view distance resident with nothing generating, lighting or decorating. Then it times the same for a fresh process reopening the world. Fast profile, offscreen, 720p, fresh dirs, A/B alternated.

Mac mini M4 Pro, 14 cores (other sessions kept its load at 33-48):

create main this PR
RD 32 in-frame: chunks at 5 s 47 / 20 387 / 1,156
RD 32 in-frame: first meshed section 1.3 / 12.6 s 1.3 / 0.9 s
RD 32 in-frame: all chunks in view 16.6 / 18.9 s 22.2 / 11.8 s
RD 32 server thread: chunks at 5 s / 10 s 181, 376 / 677, 961 348, 434 / 1,163, 1,361
RD 32 server thread: all chunks in view 27.0 / 26.0 s 22.0 / 18.7 s
RD 12 server thread: all (6 runs each, mean) 9.3 s 8.9 s (noise)

Reopening an existing world and RD 12 in-frame are unchanged within noise. In the in-frame RD 32 case, players see terrain within a second instead of a near-empty world for up to 13 s. The total time to the last chunk is within the machine's noise.

Linux, 4 threads (playhorizon, AMD EPYC 7662 limited to 4 threads with taskset -c 0-3; an emulated small CPU, not laptop hardware; rendering on llvmpipe, which takes ~1.4 of the 4 cores): no change. RD 32 server-thread create is 60.2 s on both, RD 12 in-frame 17.5-17.9 s vs 18.0-18.4 s. With 3 workers, only 9 generation jobs are in flight, so few are ever stranded. The earlier real-hardware reference (ThinkPad i5-7200U, perf-next-3): RD 12 entry 26.4 s vs vanilla 75.3 s.

Testing

  • New unit test queued_jobs_follow_the_centre_and_the_loading_screen: it reproduces the stale order (a loading-screen job behind a later, farther one) and checks the order after rank_again, for a centre move as well.
  • Parity on an integration commit of this PR and #2481 on main 4d6875ecf: chunk_generation, worldgen, worldgen_random, save_roundtrip and world_reopen identical to vanilla (5 passed, 0 failed, Mac mini). The full parity.py --changed set runs in CI's parity job.
  • pr_ready (--quick; harnesses above):

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 4d6875ecf, 5 min 54 s)

Check Result
Scope ✅ 1 files, +113 −9
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ➖ no Python change
rustfmt ✅ (16 s)
clippy ✅ (29 s)
tests: horizon-client ✅ 1336 passed (4 min 29 s)
doc tests ✅ 0 passed (5 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 79 affected, to run in CI (--quick): arrow, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, breaking_model, cauldron, chat_screen, command_exec, command_parse and 67 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

For Ludovic

Nothing to decide.

🤖 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/2480 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/requeue-on-centre-change` --- ### 📝 Commits (1) - [`8920f08`](https://github.com/horizon-rust/horizon/commit/8920f08fd9724262e03220a561518b0d9a252b7b) Streaming: rank queued jobs again when the centre or the loading screen changes ### 📊 Changes **1 file changed** (+113 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/streaming.rs` (+113 -9) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the roadmap item `world-entry` (faster world creation and entry). ## What and why Chunk jobs (generate, decorate, light, mesh) wait in a priority queue, nearest first. Each job's priority was fixed when it was queued, from the centre and mode of that moment. Two things broke the order: - **The loading screen.** While it is up, jobs are ranked ring by ring (`Ranges::rings`: `ring² << 20 | d²`). Once it closes they are ranked by plain distance (`d²`, below 2²⁰). A job queued during the loading screen therefore waited behind *every* job queued after it, however far away those were. - **The centre moving** (spawn search, the player arriving, a teleport): jobs queued for the old centre kept their old order. The jobs stranded this way included proto chunks next to the spawn. Decoration follows vanilla's order (`DecorationOrder`), so one missing proto near the player held back every decoration around it. In-frame at render distance 32 on the Mac mini, the world stayed at 15 to 47 chunks for 10 to 13 seconds while the workers generated all ~3,900 proto chunks of the area. Only then did the first decoration run. Instrumented run: the lowest-ranked chunk (−37, 8) waited on proto (−37, −1), which was "generating" (queued) from 2 s until every other proto was done. Now each queued job keeps its column and its bias (the existing `* 4 + 0/1/2` per job kind). When the centre, the extra areas, the band or the loading-screen flag change, `Streaming::requeue` computes the priorities again and rebuilds the heap. That is O(queued jobs), once per change. Vanilla's chunk task queue follows the current ticket levels in the same way. Decoration order is unaffected: it is still enforced by `DecorationOrder::blocked`, which never lets two overlapping decorations run at once. Only the order of independent jobs in the worker queue changes. ## Measured `entry_bench` (scratch driver on top of perf_bench's control socket): it times `open PerfBench 1234 creative` from the title screen to the first resident chunk, the first meshed section, and "all": every chunk of the view distance resident with nothing generating, lighting or decorating. Then it times the same for a fresh process reopening the world. Fast profile, offscreen, 720p, fresh dirs, A/B alternated. **Mac mini M4 Pro, 14 cores (other sessions kept its load at 33-48):** | create | main | this PR | |---|---|---| | RD 32 in-frame: chunks at 5 s | 47 / 20 | **387 / 1,156** | | RD 32 in-frame: first meshed section | 1.3 / **12.6** s | 1.3 / 0.9 s | | RD 32 in-frame: all chunks in view | 16.6 / 18.9 s | 22.2 / 11.8 s | | RD 32 server thread: chunks at 5 s / 10 s | 181, 376 / 677, 961 | 348, 434 / 1,163, 1,361 | | RD 32 server thread: all chunks in view | 27.0 / 26.0 s | **22.0 / 18.7 s** | | RD 12 server thread: all (6 runs each, mean) | 9.3 s | 8.9 s (noise) | Reopening an existing world and RD 12 in-frame are unchanged within noise. In the in-frame RD 32 case, players see terrain within a second instead of a near-empty world for up to 13 s. The total time to the last chunk is within the machine's noise. **Linux, 4 threads** (playhorizon, AMD EPYC 7662 limited to 4 threads with `taskset -c 0-3`; an emulated small CPU, not laptop hardware; rendering on llvmpipe, which takes ~1.4 of the 4 cores): no change. RD 32 server-thread create is 60.2 s on both, RD 12 in-frame 17.5-17.9 s vs 18.0-18.4 s. With 3 workers, only 9 generation jobs are in flight, so few are ever stranded. The earlier real-hardware reference (ThinkPad i5-7200U, perf-next-3): RD 12 entry 26.4 s vs vanilla 75.3 s. ## Testing - New unit test `queued_jobs_follow_the_centre_and_the_loading_screen`: it reproduces the stale order (a loading-screen job behind a later, farther one) and checks the order after `rank_again`, for a centre move as well. - Parity on an integration commit of this PR and #2481 on main 4d6875ecf: chunk_generation, worldgen, worldgen_random, save_roundtrip and world_reopen identical to vanilla (5 passed, 0 failed, Mac mini). The full `parity.py --changed` set runs in CI's parity job. - pr_ready (`--quick`; harnesses above): **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 4d6875ecf, 5 min 54 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +113 −9 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ➖ no Python change | | rustfmt | ✅ (16 s) | | clippy | ✅ (29 s) | | tests: horizon-client | ✅ 1336 passed (4 min 29 s) | | doc tests | ✅ 0 passed (5 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 79 affected, to run in CI (--quick): arrow, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, breaking_model, cauldron, chat_screen, command_exec, command_parse and 67 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## For Ludovic Nothing to decide. 🤖 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:16:34 +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#4355
No description provided.