[PR #352] [MERGED] Relit chunks remesh only where their light changed #2512

Closed
opened 2026-11-02 15:56:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/remesh-light-changes


📝 Commits (2)

  • 3137c7b Relit chunks remesh only where their light changed (#270)
  • e0ecbf1 Test that relit columns keep every mesh current

📊 Changes

3 files changed (+225 additions, -10 deletions)

View changed files

📝 crates/horizon-client/src/light.rs (+68 -0)
📝 crates/horizon-client/src/streaming.rs (+20 -8)
📝 crates/horizon-client/tests/streaming_meshes.rs (+137 -2)

📄 Description

Fixes #270

What

A light job for a column that was already lit now remeshes only the sections around the light that actually changed. Before, every finished light job dirtied all 24 sections of the 3x3 columns around it (216 sections), whether or not any light changed.

Why

A temporary probe (counting block writes, light-changed positions and newly dirtied sections by cause, once a second; not in this PR) showed where the ~150 s tail of #270 comes from, at RD16 (PerfBench, seed 1234):

seconds after open block writes/s sections newly dirtied/s by: block writes incremental relight finished light jobs
15 474 219 106 864
30 189 51 45 408
60 29 18 11 216
105 13 9 0 192
150 5 1 0 144

The block writes are real: fluids from worldgen springs and lakes settling (air -> water/lava states make most of them), which vanilla runs too. The last column is spurious. A fluid tick in a column that isn't lit yet (at the edge of the loaded area) sends its lit neighbours for a full light job (World::set → dirty_light), and each finished job dirtied 216 sections, while the light it computed differed in a few hundred positions at most (often none). That is about one relight per second for two and a half minutes.

Vanilla dirties only the sections whose light changed (ClientChunkCache.onLightUpdate → setSectionDirtyWithNeighbors), and only for light updates that happen.

How

  • light::apply_relighting: for a column that was lit before, it writes only the sections whose light changed (no copy-on-write for the others) and returns the changed block positions.
  • Done::Lit: a column lit for the first time still dirties its 3x3 neighbourhood (its neighbours' meshes read its light). A relit one goes through mark_light_changes, the same marking the incremental relight already uses: the sections around each changed position.

The meshes stay the same as before: a section is remeshed whenever any light it samples changed. Section rebuilds were already batched as in vanilla's SectionRenderDispatcher: one rebuild per section per frame (dirty_sections is a set), nearest first (job priority by distance).

Measurements

Mac mini M4 Pro, RD16, PerfBench world (seed 1234), offscreen, status.meshed_sections polled every 250 ms for 150 s after open. Three games per build, interleaved; means with 95% CIs (Student's t).

main this PR
sections meshed, 0–15 s (the load) 61,266 ± 11,571 20,227 ± 2,471
sections meshed, 15–148 s (the tail) 23,066 ± 9,019 6,823 ± 2,598
sections meshed, total 84,332 ± 7,524 27,051 ± 1,100 (−68%)

The tail still lasts about as long (fluids settle at vanilla's tick rate), with 3–4x fewer remeshes. Process CPU over the tail isn't a usable signal here: offscreen frames are uncapped, so the render loop takes whatever meshing gives back, and other sessions were building on the machine.

How tested

cargo fmt --all -- --check                                   OK
cargo clippy --workspace --all-targets -- -D warnings        OK
cargo test -p horizon-client                                 all passed (lib 655, integration tests)
  new: light::relighting_reports_exactly_the_changed_positions
  new: streaming_meshes::relit_columns_keep_every_mesh_current: columns sent like a server (one held back,
       so its neighbours stay unlit), edits that relight lit columns, then the missing column: every section's
       last mesh is byte-identical to a fresh mesh of the final world (fails if the first-lit 3x3 dirtying is removed)
parity.py --changed origin/main                         80 passed, 0 failed (one run on the merge
                                                             of this PR with its three siblings: #270 relight
                                                             remesh, #224 proto saves, #271 frame cap, spawn
                                                             heightmap; includes section_mesh, light, natural_spawn,
                                                             spawn_rules, world_spawn, frame_limiter, game_loop)

Nothing needs Ludovic.

🤖 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/352 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/remesh-light-changes` --- ### 📝 Commits (2) - [`3137c7b`](https://github.com/horizon-rust/horizon/commit/3137c7b97799129bc5fa4dae6ff5ff211510e7a1) Relit chunks remesh only where their light changed (#270) - [`e0ecbf1`](https://github.com/horizon-rust/horizon/commit/e0ecbf1db1dc0aaff4a88a57a550e30a1187976f) Test that relit columns keep every mesh current ### 📊 Changes **3 files changed** (+225 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/light.rs` (+68 -0) 📝 `crates/horizon-client/src/streaming.rs` (+20 -8) 📝 `crates/horizon-client/tests/streaming_meshes.rs` (+137 -2) </details> ### 📄 Description Fixes #270 ## What A light job for a column that was already lit now remeshes only the sections around the light that actually changed. Before, every finished light job dirtied all 24 sections of the 3x3 columns around it (216 sections), whether or not any light changed. ## Why A temporary probe (counting block writes, light-changed positions and newly dirtied sections by cause, once a second; not in this PR) showed where the ~150 s tail of #270 comes from, at RD16 (PerfBench, seed 1234): | seconds after `open` | block writes/s | sections newly dirtied/s by: block writes | incremental relight | finished light jobs | |---|---|---|---|---| | 15 | 474 | 219 | 106 | **864** | | 30 | 189 | 51 | 45 | **408** | | 60 | 29 | 18 | 11 | **216** | | 105 | 13 | 9 | 0 | **192** | | 150 | 5 | 1 | 0 | **144** | The block writes are real: fluids from worldgen springs and lakes settling (`air -> water/lava` states make most of them), which vanilla runs too. The last column is spurious. A fluid tick in a column that isn't lit yet (at the edge of the loaded area) sends its lit neighbours for a full light job (`World::set` → `dirty_light`), and each finished job dirtied 216 sections, while the light it computed differed in a few hundred positions at most (often none). That is about one relight per second for two and a half minutes. Vanilla dirties only the sections whose light changed (`ClientChunkCache.onLightUpdate` → `setSectionDirtyWithNeighbors`), and only for light updates that happen. ## How - `light::apply_relighting`: for a column that was lit before, it writes only the sections whose light changed (no copy-on-write for the others) and returns the changed block positions. - `Done::Lit`: a column lit for the first time still dirties its 3x3 neighbourhood (its neighbours' meshes read its light). A relit one goes through `mark_light_changes`, the same marking the incremental relight already uses: the sections around each changed position. The meshes stay the same as before: a section is remeshed whenever any light it samples changed. Section rebuilds were already batched as in vanilla's `SectionRenderDispatcher`: one rebuild per section per frame (`dirty_sections` is a set), nearest first (job priority by distance). ## Measurements Mac mini M4 Pro, RD16, PerfBench world (seed 1234), offscreen, `status.meshed_sections` polled every 250 ms for 150 s after `open`. Three games per build, interleaved; means with 95% CIs (Student's t). | | main | this PR | |---|---|---| | sections meshed, 0–15 s (the load) | 61,266 ± 11,571 | **20,227 ± 2,471** | | sections meshed, 15–148 s (the tail) | 23,066 ± 9,019 | **6,823 ± 2,598** | | sections meshed, total | 84,332 ± 7,524 | **27,051 ± 1,100** (−68%) | The tail still lasts about as long (fluids settle at vanilla's tick rate), with 3–4x fewer remeshes. Process CPU over the tail isn't a usable signal here: offscreen frames are uncapped, so the render loop takes whatever meshing gives back, and other sessions were building on the machine. ## How tested ``` cargo fmt --all -- --check OK cargo clippy --workspace --all-targets -- -D warnings OK cargo test -p horizon-client all passed (lib 655, integration tests) new: light::relighting_reports_exactly_the_changed_positions new: streaming_meshes::relit_columns_keep_every_mesh_current: columns sent like a server (one held back, so its neighbours stay unlit), edits that relight lit columns, then the missing column: every section's last mesh is byte-identical to a fresh mesh of the final world (fails if the first-lit 3x3 dirtying is removed) parity.py --changed origin/main 80 passed, 0 failed (one run on the merge of this PR with its three siblings: #270 relight remesh, #224 proto saves, #271 frame cap, spawn heightmap; includes section_mesh, light, natural_spawn, spawn_rules, world_spawn, frame_limiter, game_loop) ``` Nothing needs Ludovic. 🤖 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 15:56:49 +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#2512
No description provided.