[PR #994] [MERGED] Far terrain: bounded render-thread work while tiles generate #2972

Closed
opened 2026-11-02 16:00:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/lod-frame-spikes


📝 Commits (4)

  • bf8d849 Far terrain: no dark band at the full-detail edge, no black cliffs
  • 895dc26 Far terrain: no faces for caves nothing can see into
  • af9d888 Far terrain: time each step of Lod::update
  • c468938 Far terrain: bounded render-thread work while tiles generate

📊 Changes

6 files changed (+810 additions, -186 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+55 -26)
📝 crates/horizon-client/src/gfx.rs (+59 -14)
📝 crates/horizon-client/src/gfx/lod.rs (+120 -1)
📝 crates/horizon-client/src/gfx/resident.rs (+30 -10)
📝 crates/horizon-client/src/lod.rs (+301 -93)
📝 crates/horizon-client/src/lod/mesh.rs (+245 -42)

📄 Description

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

Follow-up to @Online5277's terrain LODs (#771): spikes on the render thread while far tiles generate. Stacked on #993 (review the last two commits: the first only adds timing spans around each step of Lod::update).

What

  • Uploads: far meshes upload within about 2 ms a frame, at least one per frame. The rest wait in lod::Pending with their removals and cutout, and apply in order: a newer mesh replaces a waiting one, and a removal drops it. A finished job can hold hundreds of tiles; it used to upload in one frame.
  • Mesh inputs: gathered across frames within about 2 ms (Gathering), from a snapshot of the active tiles' samples. They used to be gathered for every dirty tile in one frame. Tile samples are shared with mesh jobs (Arc) instead of cloned.
  • Per-frame bookkeeping: tiles are selected only when the plan, samples, covered columns or dirty tiles changed, and the covered stand-ins are added only after a replan. An invalidated chunk looks up the few tiles per level that touch it, instead of scanning every active tile. The full-detail column set is rebuilt only when a column's completeness, the center or the radius changes (Renderer::lod_detail_revision).
  • Observing chunks: far summaries are observed within about 1 ms a frame (at least one), unloaded chunks first. Each block state's kind (kept, fluid, emission) is read once into a table, instead of matching block names for every block.

LODs off is unchanged: all of this sits behind self.lod, Renderer::upload still uploads the same way, and set_detail keeps the same masks (#995 has the LODs-off trio and FPS).

Numbers

Mac mini M4 Pro, seed 1234, RD 12, LOD 256. Overview until covered, then fly 480 blocks south in 30 s (far terrain replans, meshes and uploads the whole way). Raw frame times from horizon-ctl fly, spans from HORIZON_SPIKES=0. Before (#993) and after ran in turn, twice:

frames in 30 s avg ms p99 ms max ms > 16.7 ms > 33 ms
#993 2919, 5027 10.3, 6.0 101, 61 275, 270 478, 329 211, 128
this 7203, 7197 4.2, 4.2 22, 37 64, 118 154, 241 24, 85

Worst single frame per span (ms), #993 then this: lod_update 158/184 → 34/35, lod_input 154/131 → 34/12, lod_select 157/133 → 5/30, lod_observe 253/207 → 36/46, update_world 271/239 → 37/65. The 118 ms frame in the second run is in renderer, not far terrain. The Mac was shared with other sessions (CPU 70–90% busy), which explains the run-to-run spread.

ThinkPad, Intel HD 620 (Mesa ANV, Xvfb, nice 19), RD 12, LOD 64, after coverage (#995's pacing is idle by then and its cap starts above 64, so this is this PR's effect):

build covered in FPS overview / meadow / peak 1% low CPU ms
#993 711 s 102.7 / 119.6 / 103.5 76.4 / 109.8 / 23.7 4.98 / 3.87 / 6.08
this + #995 702 s 105.8 / 120.5 / 104.6 99.3 / 105.0 / 49.0 4.15 / 3.57 / 5.93

The same picture appears while tiles generate on the HD 620; see #995.

Screenshots: fin-*-a1-b1-d1.png in ~/code/horizon-parity/shots/perf-frame-9/. Same image (no change to meshes).

Self-check

cargo fmt --all --check                                    ok
cargo clippy --workspace --all-targets -- -D warnings      ok
cargo test -p horizon-client --lib                         924 passed, 13 ignored
  ignored real_mesh_clips_near_chunks_… (worker seam)       ok
tools/parity.py --changed origin/main                      98 passed, 0 failed (run on the whole stack)

New test: joined_jobs_apply_as_if_in_turn. The worker-seam test now marks reselect when it edits the plan by hand, as a replan does.

Kira: card#23.

🤖 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/994 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/lod-frame-spikes` --- ### 📝 Commits (4) - [`bf8d849`](https://github.com/horizon-rust/horizon/commit/bf8d84930fe5675d4bb667220d48a1d347c13715) Far terrain: no dark band at the full-detail edge, no black cliffs - [`895dc26`](https://github.com/horizon-rust/horizon/commit/895dc26848cef7ca0e10badc2a3030ea7252748d) Far terrain: no faces for caves nothing can see into - [`af9d888`](https://github.com/horizon-rust/horizon/commit/af9d88841075a1af5ff2b1ac1d1c1e689084b043) Far terrain: time each step of Lod::update - [`c468938`](https://github.com/horizon-rust/horizon/commit/c468938a66acd102c4adef86848b1b060b5985e6) Far terrain: bounded render-thread work while tiles generate ### 📊 Changes **6 files changed** (+810 additions, -186 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+55 -26) 📝 `crates/horizon-client/src/gfx.rs` (+59 -14) 📝 `crates/horizon-client/src/gfx/lod.rs` (+120 -1) 📝 `crates/horizon-client/src/gfx/resident.rs` (+30 -10) 📝 `crates/horizon-client/src/lod.rs` (+301 -93) 📝 `crates/horizon-client/src/lod/mesh.rs` (+245 -42) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Follow-up to @Online5277's terrain LODs (#771): spikes on the render thread while far tiles generate. Stacked on #993 (review the last two commits: the first only adds timing spans around each step of `Lod::update`). ## What - **Uploads:** far meshes upload within about 2 ms a frame, at least one per frame. The rest wait in `lod::Pending` with their removals and cutout, and apply in order: a newer mesh replaces a waiting one, and a removal drops it. A finished job can hold hundreds of tiles; it used to upload in one frame. - **Mesh inputs:** gathered across frames within about 2 ms (`Gathering`), from a snapshot of the active tiles' samples. They used to be gathered for every dirty tile in one frame. Tile samples are shared with mesh jobs (`Arc`) instead of cloned. - **Per-frame bookkeeping:** tiles are selected only when the plan, samples, covered columns or dirty tiles changed, and the covered stand-ins are added only after a replan. An invalidated chunk looks up the few tiles per level that touch it, instead of scanning every active tile. The full-detail column set is rebuilt only when a column's completeness, the center or the radius changes (`Renderer::lod_detail_revision`). - **Observing chunks:** far summaries are observed within about 1 ms a frame (at least one), unloaded chunks first. Each block state's kind (kept, fluid, emission) is read once into a table, instead of matching block names for every block. LODs off is unchanged: all of this sits behind `self.lod`, `Renderer::upload` still uploads the same way, and `set_detail` keeps the same masks (#995 has the LODs-off trio and FPS). ## Numbers **Mac mini M4 Pro**, seed 1234, RD 12, LOD 256. Overview until covered, then fly 480 blocks south in 30 s (far terrain replans, meshes and uploads the whole way). Raw frame times from `horizon-ctl fly`, spans from `HORIZON_SPIKES=0`. Before (#993) and after ran in turn, twice: | | frames in 30 s | avg ms | p99 ms | max ms | > 16.7 ms | > 33 ms | | --- | --- | --- | --- | --- | --- | --- | | #993 | 2919, 5027 | 10.3, 6.0 | 101, 61 | 275, 270 | 478, 329 | 211, 128 | | this | **7203, 7197** | **4.2, 4.2** | **22, 37** | **64, 118** | **154, 241** | **24, 85** | Worst single frame per span (ms), #993 then this: `lod_update` 158/184 → **34/35**, `lod_input` 154/131 → **34/12**, `lod_select` 157/133 → **5/30**, `lod_observe` 253/207 → **36/46**, `update_world` 271/239 → **37/65**. The 118 ms frame in the second run is in `renderer`, not far terrain. The Mac was shared with other sessions (CPU 70–90% busy), which explains the run-to-run spread. **ThinkPad, Intel HD 620** (Mesa ANV, Xvfb, nice 19), RD 12, LOD 64, after coverage (#995's pacing is idle by then and its cap starts above 64, so this is this PR's effect): | build | covered in | FPS overview / meadow / peak | 1% low | CPU ms | | --- | --- | --- | --- | --- | | #993 | 711 s | 102.7 / 119.6 / 103.5 | 76.4 / 109.8 / 23.7 | 4.98 / 3.87 / 6.08 | | this + #995 | 702 s | 105.8 / 120.5 / 104.6 | **99.3 / 105.0 / 49.0** | **4.15 / 3.57 / 5.93** | The same picture appears while tiles generate on the HD 620; see #995. Screenshots: `fin-*-a1-b1-d1.png` in `~/code/horizon-parity/shots/perf-frame-9/`. Same image (no change to meshes). ## Self-check ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client --lib 924 passed, 13 ignored ignored real_mesh_clips_near_chunks_… (worker seam) ok tools/parity.py --changed origin/main 98 passed, 0 failed (run on the whole stack) ``` New test: `joined_jobs_apply_as_if_in_turn`. The worker-seam test now marks `reselect` when it edits the plan by hand, as a replan does. Kira: card#23. 🤖 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-02 16:00:32 +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#2972
No description provided.