[PR #4157] [MERGED] Far terrain: real chunks out to level 2 on idle threads, loading outward from the player #5448

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4157
Author: @spidercraft
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @rdbtCVS

Base: main ← Head: far-terrain-speed


📝 Commits (3)

  • 2e321e3 Far terrain: decorated chunks kept on disk, read again next session
  • 8922550 Far terrain cache: a chunk cached already is not written again
  • fb9db82 Far terrain: real chunks out to level 2 on idle threads, loading outward from the player

📊 Changes

5 files changed (+538 additions, -178 deletions)

View changed files

📝 crates/horizon-client-render/src/lod.rs (+109 -156)
➕ crates/horizon-client-render/src/lod/cache.rs (+356 -0)
📝 crates/horizon-client/src/game.rs (+0 -1)
📝 crates/horizon-client/src/save.rs (+31 -2)
📝 crates/horizon-client/src/vanillagen/lod.rs (+42 -19)

📄 Description

🤖 Opened by Claude Code.

Far terrain, part 2 of 4. This PR: faster loading, outward from the player. Built on #4156 (part 1, the disk cache: merge it first; this branch contains it, so review this PR's own commit). Next: #4158 (light and water), #4159 (fades).

What and why

Far terrain filled in slowly, and in a cone ahead of the view, with coarse tiles first even beside the player.

  • Decoration (real trees and structures) runs on a third of the threads, up to 12, at idle priority (horizon_threads::idle_current), instead of one. It only takes time the near chunks and the frame leave.
  • 8×8 decoration batches instead of 4×4. A batch needs a two-chunk border of proto chunks, and the protos (noise, surface) are most of the cost (1.06 s of 1.21 s for 48 chunks): 2.25 protos a chunk instead of 4, 16.6 ms a chunk instead of 26.9.
  • Decorated out to level 2 (cells of 4 blocks, about 1024 blocks out), not only levels 0 and 1. A detail request asks for up to 512 chunks instead of 32, which capped detail at one decoration thread's pace.
  • Meshing splits each job across the sampling threads (sampling_threads), each with its own material cache, instead of the far terrain thread alone.
  • Only the tiles the plan keeps are sampled, each at the level its distance calls for, nearest first, whichever way the player looks: far terrain grows outward in rings. Before, the coarsest tiles went first at top priority and every other job was a broad refinement, so beside the player a coarse tile was built and replaced moments later. The view-ahead focus, TileKey::in_view and Lod::update's yaw go.
  • Stop flags are set under the lock their threads wait on (Lod::drop, the samplers' stop, Builder::drop). A thread between its check and its wait missed the wake, and closing the world waited forever. Two hung test runs found it (more threads made it likely); the formerly hanging test then passed five runs in a row.

Measured

Fresh world, seed 1234, LOD Distance 512, render distance 12, on a 32-thread CPU, frame rate at its 120 fps cap throughout:

every tile sampled refined far cells at 20 s at 40 s
main about 15 s 368k 447k
this PR about 12 s 390k 500k

Machines with 4 threads or fewer keep their hold on far terrain while the near chunks load (held).

Tests

The scheduling tests check the nearest final tile goes first, the next ring follows, a coarse tile is never sampled under its fine ones, and the larger detail request.

pr_ready on the top of this stack (#4159, which contains this PR):

pr_ready (tools/pr_ready.py --quick on SpiderPC, against origin/main at 25f9cd3a9, 2 min 15 s)

Check Result
Scope ⚠️ 12 files, +1175 −295; 1470 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (26 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 0 s)
tests: horizon-client, horizon-client-render ✅ 1527 passed (43 s)
doc tests ✅ 0 passed (2 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 ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/4157 **Author:** [@spidercraft](https://github.com/spidercraft) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `far-terrain-speed` --- ### 📝 Commits (3) - [`2e321e3`](https://github.com/horizon-rust/horizon/commit/2e321e385a769bcaaff350c4fb194c89eefbfd1a) Far terrain: decorated chunks kept on disk, read again next session - [`8922550`](https://github.com/horizon-rust/horizon/commit/8922550fdf258558b0a03609772168ce8c5fe6d6) Far terrain cache: a chunk cached already is not written again - [`fb9db82`](https://github.com/horizon-rust/horizon/commit/fb9db82d1b32968e3ab419498cefefe39c733a2f) Far terrain: real chunks out to level 2 on idle threads, loading outward from the player ### 📊 Changes **5 files changed** (+538 additions, -178 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/lod.rs` (+109 -156) ➕ `crates/horizon-client-render/src/lod/cache.rs` (+356 -0) 📝 `crates/horizon-client/src/game.rs` (+0 -1) 📝 `crates/horizon-client/src/save.rs` (+31 -2) 📝 `crates/horizon-client/src/vanillagen/lod.rs` (+42 -19) </details> ### 📄 Description > 🤖 Opened by Claude Code. **Far terrain, part 2 of 4.** This PR: faster loading, outward from the player. Built on #4156 (part 1, the disk cache: merge it first; this branch contains it, so review this PR's own commit). Next: #4158 (light and water), #4159 (fades). ## What and why Far terrain filled in slowly, and in a cone ahead of the view, with coarse tiles first even beside the player. - **Decoration** (real trees and structures) runs on a third of the threads, up to 12, at idle priority (`horizon_threads::idle_current`), instead of one. It only takes time the near chunks and the frame leave. - **8×8 decoration batches** instead of 4×4. A batch needs a two-chunk border of proto chunks, and the protos (noise, surface) are most of the cost (1.06 s of 1.21 s for 48 chunks): 2.25 protos a chunk instead of 4, **16.6 ms a chunk instead of 26.9**. - **Decorated out to level 2** (cells of 4 blocks, about 1024 blocks out), not only levels 0 and 1. A detail request asks for up to 512 chunks instead of 32, which capped detail at one decoration thread's pace. - **Meshing** splits each job across the sampling threads (`sampling_threads`), each with its own material cache, instead of the far terrain thread alone. - **Only the tiles the plan keeps are sampled**, each at the level its distance calls for, nearest first, whichever way the player looks: far terrain grows outward in rings. Before, the coarsest tiles went first at top priority and every other job was a broad refinement, so beside the player a coarse tile was built and replaced moments later. The view-ahead focus, `TileKey::in_view` and `Lod::update`'s yaw go. - **Stop flags are set under the lock their threads wait on** (`Lod::drop`, the samplers' stop, `Builder::drop`). A thread between its check and its wait missed the wake, and closing the world waited forever. Two hung test runs found it (more threads made it likely); the formerly hanging test then passed five runs in a row. ## Measured Fresh world, seed 1234, LOD Distance 512, render distance 12, on a 32-thread CPU, frame rate at its 120 fps cap throughout: | | every tile sampled | refined far cells at 20 s | at 40 s | |---|---|---|---| | main | about 15 s | 368k | 447k | | this PR | about 12 s | 390k | 500k | Machines with 4 threads or fewer keep their hold on far terrain while the near chunks load (`held`). ## Tests The scheduling tests check the nearest final tile goes first, the next ring follows, a coarse tile is never sampled under its fine ones, and the larger detail request. pr_ready on the top of this stack (#4159, which contains this PR): **pr_ready** (`tools/pr_ready.py --quick` on SpiderPC, against origin/main at 25f9cd3a9, 2 min 15 s) | Check | Result | | --- | --- | | Scope | ⚠️ 12 files, +1175 −295; 1470 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (26 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 0 s) | | tests: horizon-client, horizon-client-render | ✅ 1527 passed (43 s) | | doc tests | ✅ 0 passed (2 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 | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 05:12:39 +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#5448
No description provided.