[PR #866] [MERGED] Light changes dirty sections by section, not cell by cell #2870

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

📋 Pull Request Information

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

Base: main ← Head: perf/light-dirty-sections


📝 Commits (1)

  • 6bf479e Light changes dirty sections by section, not cell by cell

📊 Changes

3 files changed (+199 additions, -62 deletions)

View changed files

📝 crates/horizon-client/examples/light_parity.rs (+9 -2)
📝 crates/horizon-client/src/light.rs (+173 -31)
📝 crates/horizon-client/src/streaming.rs (+17 -29)

📄 Description

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

What

Light changes now mark dirty sections per section instead of per cell, the way vanilla's LevelRenderer collects them as a set of dirty sections.

  • light::relight and apply_relighting used to return every changed cell as a Vec<(x, y, z)>. streaming::mark_light_changes then sorted it, deduped it, and marked the 27 sections around each cell.
  • They now fill a LightChanges: one entry per touched section with a 27-bit mask saying where in the section the changes were (low face, inside or high face on each axis). dirty_sections uses the mask to mark exactly the neighbours a cell at that place can reach, so the dirty set is the same as before. mark_light_changes updates the light log once per section.
  • A new test, changes_dirty_the_sections_within_a_block_of_each_cell, checks the result against the brute-force 27-neighbour set.

Why

The brief measured about 2.9 ms per frame in light updates from block edits at RD 32 while exploring, a quarter of it in the sort and dedup of changed cells. That work is now gone: no list of cells, no sort, and the light log and dirty set get one update per section instead of one per cell.

Before / after

Mac mini, RD 32, a 60 s flight from x −960 to 0 over new terrain, probe spans averaged over the flight, two ABBA pairs. The machine was shared with other sessions (load ~100), so whole-frame numbers are noisy; the spans are the comparison.

ms per frame before (2 runs) after (2 runs)
sort + dedup of changed cells 0.052 / 0.088 0 (removed)
marking dirty sections and the light log 0.022 / 0.018 0.001 / 0.000
changed cells per frame 141 / 217 n/a (sections only)
relighting from edits, total 0.34 / 0.50 0.49 / 0.34

What remains in relighting is the light BFS itself, which this PR doesn't change. During my runs it averaged 0.3–0.5 ms per frame, less than the 2.9 ms in the brief; that number was probably taken during bigger edit bursts.

This PR changes when sections are marked, not how light is computed: the set of dirty sections is the same (see the test), and light_parity passes.

How tested (self-check)

On one integration commit of the three PRs (perf/compact-terrain-vertex, perf/light-dirty-sections, perf/mesh-queue-columns) on origin/main e508a5ce, Mac mini:

cargo fmt --all --check                                        ok
cargo clippy --workspace --all-targets -- -D warnings          ok, no warnings
cargo test -p horizon-client --lib                             870 passed, 0 failed, 11 ignored
cargo build -p horizon-client --bin horizon-client             ok
tools/parity.py --changed origin/main                          95 of 95 passed, 0 failed (155.9 min)

The harnesses covering the changed code passed: section_mesh, translucency and light. tooltip_display and mob_ai, which fail on main, also passed here. origin/main has moved since then (#859, #860); neither touches these files.

🤖 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/866 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/light-dirty-sections` --- ### 📝 Commits (1) - [`6bf479e`](https://github.com/horizon-rust/horizon/commit/6bf479ec0bb7501b34b59b40cfe18244cedb4900) Light changes dirty sections by section, not cell by cell ### 📊 Changes **3 files changed** (+199 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/light_parity.rs` (+9 -2) 📝 `crates/horizon-client/src/light.rs` (+173 -31) 📝 `crates/horizon-client/src/streaming.rs` (+17 -29) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Light changes now mark dirty sections per section instead of per cell, the way vanilla's `LevelRenderer` collects them as a set of dirty sections. - `light::relight` and `apply_relighting` used to return every changed cell as a `Vec<(x, y, z)>`. `streaming::mark_light_changes` then sorted it, deduped it, and marked the 27 sections around each cell. - They now fill a `LightChanges`: one entry per touched section with a 27-bit mask saying where in the section the changes were (low face, inside or high face on each axis). `dirty_sections` uses the mask to mark exactly the neighbours a cell at that place can reach, so the dirty set is the same as before. `mark_light_changes` updates the light log once per section. - A new test, `changes_dirty_the_sections_within_a_block_of_each_cell`, checks the result against the brute-force 27-neighbour set. ## Why The brief measured about 2.9 ms per frame in light updates from block edits at RD 32 while exploring, a quarter of it in the sort and dedup of changed cells. That work is now gone: no list of cells, no sort, and the light log and dirty set get one update per section instead of one per cell. ## Before / after Mac mini, RD 32, a 60 s flight from x −960 to 0 over new terrain, probe spans averaged over the flight, two ABBA pairs. The machine was shared with other sessions (load ~100), so whole-frame numbers are noisy; the spans are the comparison. | ms per frame | before (2 runs) | after (2 runs) | | --- | --- | --- | | sort + dedup of changed cells | 0.052 / 0.088 | **0** (removed) | | marking dirty sections and the light log | 0.022 / 0.018 | **0.001 / 0.000** | | changed cells per frame | 141 / 217 | n/a (sections only) | | relighting from edits, total | 0.34 / 0.50 | 0.49 / 0.34 | What remains in relighting is the light BFS itself, which this PR doesn't change. During my runs it averaged 0.3–0.5 ms per frame, less than the 2.9 ms in the brief; that number was probably taken during bigger edit bursts. This PR changes when sections are marked, not how light is computed: the set of dirty sections is the same (see the test), and `light_parity` passes. ## How tested (self-check) On one integration commit of the three PRs (perf/compact-terrain-vertex, perf/light-dirty-sections, perf/mesh-queue-columns) on origin/main `e508a5ce`, Mac mini: ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok, no warnings cargo test -p horizon-client --lib 870 passed, 0 failed, 11 ignored cargo build -p horizon-client --bin horizon-client ok tools/parity.py --changed origin/main 95 of 95 passed, 0 failed (155.9 min) ``` The harnesses covering the changed code passed: section_mesh, translucency and light. tooltip_display and mob_ai, which fail on main, also passed here. origin/main has moved since then (#859, #860); neither touches these files. 🤖 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:59:44 +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#2870
No description provided.