[PR #1029] [MERGED] Far terrain: chunk summaries and mesh inputs on the worker #3001

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

📋 Pull Request Information

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

Base: main ← Head: perf/lod-worker-inputs


📝 Commits (1)

  • 2193559 Far terrain: chunk summaries and mesh inputs on the worker

📊 Changes

2 files changed (+192 additions, -183 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+13 -24)
📝 crates/horizon-client/src/lod.rs (+179 -159)

📄 Description

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

Follow-up to @Online5277's terrain LODs (#771) and #994: the last far-terrain work on the render thread moves to the far-terrain worker. Builds on #994 and #995 (merged).

What

  • Chunk summaries: Lod::observe summarized each observed chunk on the render thread (256 columns, seven light reads per block), at least one chunk a frame within about 1 ms. It now hands the chunk to the worker: the latest one per column, queued once (Shared::observed). The worker returns the summary with its reductions (Done::Observed). An unchanged summary is dropped; a new one is kept and applied exactly as a reduction was (finish_observed → finish_detail). The old Job::Reduce round trip is gone.
  • Mesh inputs: #994 gathered each mesh job's inputs (neighbour edges, visited columns) on the render thread, at least one tile a frame within about 2 ms. A large tile still cost tens of milliseconds. A mesh job now carries a snapshot of the active tiles, their samples and the visited summaries (maps of Arcs, cheap to clone), and the worker gathers every tile's inputs before meshing it. This is what happened before #994, only off the render thread.
  • Copy-on-write guard: an edit copies a chunk the worker still holds (Arc::make_mut), so at most OBSERVE_AHEAD (8) resident chunks wait at once. Unloaded chunks always go, first, as before.

LODs off is unchanged: everything sits behind self.lod.

Numbers

ThinkPad, Intel HD 620, 2 cores / 4 threads (Mesa ANV, Xvfb, nice 19), seed 1234, RD 12, LOD 64. Launch, near terrain settled, then fly 480 blocks south in 30 s while far terrain is still generating. Raw frame times from horizon-ctl fly; spans from HORIZON_SPIKES=0. Builds ran in turn, #995 / this / #995 / this:

build frames in 30 s avg ms p99 ms frames > 16.7 ms > 33 ms update_world avg / worst ms lod_observe avg / worst lod_input avg / worst
#995 2991, 3842 10.0, 7.8 40.8, 27.1 392, 256 52, 18 4.45 / 64.9, 2.99 / 39.0 3.97 / 43.3, 2.67 / 22.6 0.15 / 13.8, 0.11 / 12.4
this 4109, 3995 7.3, 7.5 28.0, 30.0 146, 144 22, 29 0.24 / 26.9, 0.23 / 28.0 gone gone

The render thread's far-terrain bookkeeping (update_world) drops from 3–4.5 ms a frame to 0.24 ms, and frames over 16.7 ms drop by 45–60%. The worst frames that remain come from renderer / encode (GPU waits and submission), not from far terrain: see "What's next".

Mac mini M4 Pro, RD 12, LOD 256, overview until covered, then the same fly. The Mac was shared with other sessions (70–90% CPU busy), so only the far-terrain spans are meaningful. Worst lod_observe frame over four #995 runs: 22.6, 80.6, 27.3, 44.1 ms; worst lod_input: 8.1, 59.4, 14.6, 21.0 ms. Both are gone with this PR, and the observe span is now under 2.1 ms (queueing only).

Picture

Same meshes: the inputs are the same data, gathered on another thread. Screenshots (Mac, RD 12, overview / meadow / peak, ~/code/horizon-parity/shots/perf-frame-10/shots/, private repo):

  • LOD 64, #995 / this / #995: overview 42 / 0 px, meadow 0 / 0 px, peak 1404 / 1256 px. #995 against itself differs by 42 / 0 / 148 px. At peak the differing pixels sit in one far band in the fog, where detail tiles refine at different times between runs: at capture this build had refined 306k samples against 343k for #995. Crop with the differing pixels in red: peak-crop-b.png.
  • LOD off, #995 / this / #995: this build matches the first #995 run pixel for pixel in all three views. The two #995 runs differ by 181 px at the overview.

What's next

On the HD 620 at RD 12 / LOD 64, far terrain costs about 5 ms of GPU time. A draw-time knob, measured once every tile was sampled, shows that GPU time follows the far quad count (data in the shots folder above):

far tiles drawn GPU ms overview / meadow / peak
all 10.1 / 8.7 / 9.8
without side faces at levels ≥ 1 7.7 / 6.5 / 7.4
without any side faces 6.7 / 5.8 / 7.3
none 4.9 / 4.1 / 5.4

Side faces are 70–75% of far quads. Almost all of them are one-block terrain steps in level 0–2 tiles, 192–1024 blocks out, and none can be cut without changing the picture. The worst frames left while flying come from renderer / encode.

Self-check

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

Updated test: the worker-seam test (real_mesh_clips_near_chunks_and_preserves_water_and_edited_surfaces) now receives the worker's summary, checks that an unchanged observation keeps the old summary, and that a late seed reduction can't restore a pre-edit column.

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/1029 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/lod-worker-inputs` --- ### 📝 Commits (1) - [`2193559`](https://github.com/horizon-rust/horizon/commit/2193559cb1c9ce92b4a17af2c1fc5e8b6e1ac24e) Far terrain: chunk summaries and mesh inputs on the worker ### 📊 Changes **2 files changed** (+192 additions, -183 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+13 -24) 📝 `crates/horizon-client/src/lod.rs` (+179 -159) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Follow-up to @Online5277's terrain LODs (#771) and #994: the last far-terrain work on the render thread moves to the far-terrain worker. Builds on #994 and #995 (merged). ## What - **Chunk summaries:** `Lod::observe` summarized each observed chunk on the render thread (256 columns, seven light reads per block), at least one chunk a frame within about 1 ms. It now hands the chunk to the worker: the latest one per column, queued once (`Shared::observed`). The worker returns the summary with its reductions (`Done::Observed`). An unchanged summary is dropped; a new one is kept and applied exactly as a reduction was (`finish_observed` → `finish_detail`). The old `Job::Reduce` round trip is gone. - **Mesh inputs:** #994 gathered each mesh job's inputs (neighbour edges, visited columns) on the render thread, at least one tile a frame within about 2 ms. A large tile still cost tens of milliseconds. A mesh job now carries a snapshot of the active tiles, their samples and the visited summaries (maps of `Arc`s, cheap to clone), and the worker gathers every tile's inputs before meshing it. This is what happened before #994, only off the render thread. - **Copy-on-write guard:** an edit copies a chunk the worker still holds (`Arc::make_mut`), so at most `OBSERVE_AHEAD` (8) resident chunks wait at once. Unloaded chunks always go, first, as before. LODs off is unchanged: everything sits behind `self.lod`. ## Numbers **ThinkPad, Intel HD 620, 2 cores / 4 threads** (Mesa ANV, Xvfb, nice 19), seed 1234, RD 12, LOD 64. Launch, near terrain settled, then fly 480 blocks south in 30 s while far terrain is still generating. Raw frame times from `horizon-ctl fly`; spans from `HORIZON_SPIKES=0`. Builds ran in turn, #995 / this / #995 / this: | build | frames in 30 s | avg ms | p99 ms | frames > 16.7 ms | > 33 ms | `update_world` avg / worst ms | `lod_observe` avg / worst | `lod_input` avg / worst | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | #995 | 2991, 3842 | 10.0, 7.8 | 40.8, 27.1 | 392, 256 | 52, 18 | 4.45 / 64.9, 2.99 / 39.0 | 3.97 / 43.3, 2.67 / 22.6 | 0.15 / 13.8, 0.11 / 12.4 | | this | **4109, 3995** | **7.3, 7.5** | 28.0, 30.0 | **146, 144** | 22, 29 | **0.24 / 26.9, 0.23 / 28.0** | gone | gone | The render thread's far-terrain bookkeeping (`update_world`) drops from 3–4.5 ms a frame to 0.24 ms, and frames over 16.7 ms drop by 45–60%. The worst frames that remain come from `renderer` / `encode` (GPU waits and submission), not from far terrain: see "What's next". **Mac mini M4 Pro**, RD 12, LOD 256, overview until covered, then the same fly. The Mac was shared with other sessions (70–90% CPU busy), so only the far-terrain spans are meaningful. Worst `lod_observe` frame over four #995 runs: 22.6, 80.6, 27.3, 44.1 ms; worst `lod_input`: 8.1, 59.4, 14.6, 21.0 ms. Both are gone with this PR, and the observe span is now under 2.1 ms (queueing only). ## Picture Same meshes: the inputs are the same data, gathered on another thread. Screenshots (Mac, RD 12, overview / meadow / peak, `~/code/horizon-parity/shots/perf-frame-10/shots/`, private repo): - LOD 64, #995 / this / #995: overview 42 / 0 px, meadow 0 / 0 px, peak 1404 / 1256 px. #995 against itself differs by 42 / 0 / 148 px. At peak the differing pixels sit in one far band in the fog, where detail tiles refine at different times between runs: at capture this build had refined 306k samples against 343k for #995. Crop with the differing pixels in red: `peak-crop-b.png`. - LOD off, #995 / this / #995: this build matches the first #995 run pixel for pixel in all three views. The two #995 runs differ by 181 px at the overview. ## What's next On the HD 620 at RD 12 / LOD 64, far terrain costs about 5 ms of GPU time. A draw-time knob, measured once every tile was sampled, shows that GPU time follows the far quad count (data in the shots folder above): | far tiles drawn | GPU ms overview / meadow / peak | | --- | --- | | all | 10.1 / 8.7 / 9.8 | | without side faces at levels ≥ 1 | 7.7 / 6.5 / 7.4 | | without any side faces | 6.7 / 5.8 / 7.3 | | none | 4.9 / 4.1 / 5.4 | Side faces are 70–75% of far quads. Almost all of them are one-block terrain steps in level 0–2 tiles, 192–1024 blocks out, and none can be cut without changing the picture. The worst frames left while flying come from `renderer` / `encode`. ## Self-check ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client --lib 929 passed, 13 ignored ignored real_mesh_clips_near_chunks_… (worker seam) ok tools/parity.py --changed origin/main 98 passed, 0 failed ``` Updated test: the worker-seam test (`real_mesh_clips_near_chunks_and_preserves_water_and_edited_surfaces`) now receives the worker's summary, checks that an unchanged observation keeps the old summary, and that a late seed reduction can't restore a pre-edit column. 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:45 +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#3001
No description provided.