[PR #3961] [MERGED] Streaming: light and mesh jobs bounded in flight, nearest first #5324

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3961
Author: @WhyFovius
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: perf/chunk-streaming-priority


📝 Commits (1)

  • 89b737d Streaming: light and mesh jobs bounded in flight, nearest first

📊 Changes

1 file changed (+162 additions, -5 deletions)

View changed files

📝 crates/horizon-client-render/src/streaming.rs (+162 -5)

📄 Description

> 🤖 Opened by WhyFovius's AI agent (OpenCode, GLM), not by WhyFovius personally.

What and why

The light and mesh stages of Streaming::update submitted every ready column's jobs at once, in hash order, with no bound on what is in flight. Generation (workers * 3) and decoration (workers * 2) were already bounded; light and mesh were not. At a wide render distance:

  • every unlit column got a Job::Light and every dirty in-view column got up to 24 Job::Mesh entries, each carrying its own 3x3 region snapshot, so the queue, lighting and meshing grew with the number of loaded columns (at the reporter's render distance 1000, millions of entries);
  • requeue re-ranked that whole heap under the worker queue's mutex every time the player crossed a chunk border;
  • the workers ground through far jobs whose columns went stale long before a worker reached them (their results dropped only after the work was done), and the backlog survived lowering the render distance, because queued jobs are never cancelled — so chunks around the player waited behind it (#3629: "when I run, chunks barely load around me... after playing for a while the game starts lagging again, even with 32/12").

Both stages now hand the workers only as much as they can chew (nearest_first): the ready candidates are ranked by the current distance each update, and only the nearest room are submitted — light workers * 4 columns, mesh workers * 32 sections. What stays dirty is asked for again, with the current centre, as capacity frees, so what runs is always the nearest of what is left; requeue then has a small queue to keep close. The mesh stage's readiness check (light_region_ready, light_region without its snapshot) is factored out so the ranking does not build regions it will not submit.

Player-visible effect: terrain around a moving player is always worked on first, and the job queue no longer grows with the render distance or survives lowering it.

Vanilla reference

Vanilla's chunk system works the same way: ChunkTaskPriorityQueue holds bounded per-worker queues and reschedules the rest as ticket levels (and the player) move, and ThreadedLevelLightEngine submits light tasks through the same queues rather than queueing a whole world's worth at once. The gating of each stage (a column lights when its 3x3 exists, meshes when its 3x3 is lit) is unchanged — only the submission is bounded and ordered. No parity-visible behavior changes: harness order (rings while the level loading screen is up) is kept, since the ordering key is the same Ranges::priority the queue uses.

Self-check

pr_ready (tools/pr_ready.py --quick --base origin/main on REIMAGINEDOS, against origin/main at 90aded96a, 2 min 35 s)

Check Result
Scope 1 file, +162 -5
Cargo.lock unchanged
Public tree pass
Python tests 444 passed (49 s)
rustfmt pass (7 s)
clippy pass (1 min 2 s)
tests: horizon-client-render 552 passed (22 s)
doc tests 0 passed (10 s)
content root tests content root untouched
tokens.css up to date theme untouched
launcher rustfmt/clippy/tests launcher untouched
Parity not run (--quick): CI's parity job picks the affected harnesses
Label no label: a fix

New unit tests: bounded_submission_takes_the_nearest_first (bounded, nearest, deterministic) and light_readiness_follows_the_region_a_light_job_reads (the readiness walk: finished columns, decorated protos past the area, checked-out protos, in-range gaps).

Fixes #3629

🤖 Generated with OpenCode


🔄 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/3961 **Author:** [@WhyFovius](https://github.com/WhyFovius) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `perf/chunk-streaming-priority` --- ### 📝 Commits (1) - [`89b737d`](https://github.com/horizon-rust/horizon/commit/89b737d88aeb315ea6cb20d96d09332e2551d814) Streaming: light and mesh jobs bounded in flight, nearest first ### 📊 Changes **1 file changed** (+162 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/streaming.rs` (+162 -5) </details> ### 📄 Description > 🤖 Opened by WhyFovius's AI agent (OpenCode, GLM), not by WhyFovius personally. ## What and why The light and mesh stages of `Streaming::update` submitted every ready column's jobs at once, in hash order, with no bound on what is in flight. Generation (`workers * 3`) and decoration (`workers * 2`) were already bounded; light and mesh were not. At a wide render distance: - every unlit column got a `Job::Light` and every dirty in-view column got up to 24 `Job::Mesh` entries, each carrying its own 3x3 region snapshot, so the queue, `lighting` and `meshing` grew with the number of loaded columns (at the reporter's render distance 1000, millions of entries); - `requeue` re-ranked that whole heap under the worker queue's mutex every time the player crossed a chunk border; - the workers ground through far jobs whose columns went stale long before a worker reached them (their results dropped only after the work was done), and the backlog survived lowering the render distance, because queued jobs are never cancelled — so chunks around the player waited behind it (#3629: "when I run, chunks barely load around me... after playing for a while the game starts lagging again, even with 32/12"). Both stages now hand the workers only as much as they can chew (`nearest_first`): the ready candidates are ranked by the current distance each `update`, and only the nearest `room` are submitted — light `workers * 4` columns, mesh `workers * 32` sections. What stays dirty is asked for again, with the current centre, as capacity frees, so what runs is always the nearest of what is left; `requeue` then has a small queue to keep close. The mesh stage's readiness check (`light_region_ready`, `light_region` without its snapshot) is factored out so the ranking does not build regions it will not submit. Player-visible effect: terrain around a moving player is always worked on first, and the job queue no longer grows with the render distance or survives lowering it. ## Vanilla reference Vanilla's chunk system works the same way: `ChunkTaskPriorityQueue` holds bounded per-worker queues and reschedules the rest as ticket levels (and the player) move, and `ThreadedLevelLightEngine` submits light tasks through the same queues rather than queueing a whole world's worth at once. The gating of each stage (a column lights when its 3x3 exists, meshes when its 3x3 is lit) is unchanged — only the submission is bounded and ordered. No parity-visible behavior changes: harness order (rings while the level loading screen is up) is kept, since the ordering key is the same `Ranges::priority` the queue uses. ## Self-check pr_ready (tools/pr_ready.py --quick --base origin/main on REIMAGINEDOS, against origin/main at 90aded96a, 2 min 35 s) | Check | Result | | --- | --- | | Scope | 1 file, +162 -5 | | Cargo.lock | unchanged | | Public tree | pass | | Python tests | 444 passed (49 s) | | rustfmt | pass (7 s) | | clippy | pass (1 min 2 s) | | tests: horizon-client-render | 552 passed (22 s) | | doc tests | 0 passed (10 s) | | content root tests | content root untouched | | tokens.css up to date | theme untouched | | launcher rustfmt/clippy/tests | launcher untouched | | Parity | not run (--quick): CI's parity job picks the affected harnesses | | Label | no label: a fix | New unit tests: `bounded_submission_takes_the_nearest_first` (bounded, nearest, deterministic) and `light_readiness_follows_the_region_a_light_job_reads` (the readiness walk: finished columns, decorated protos past the area, checked-out protos, in-range gaps). Fixes #3629 🤖 Generated with [OpenCode](https://opencode.ai) --- <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:47 +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#5324
No description provided.