[PR #4386] [MERGED] Chunk lighting: reuse worker scratch buffers and optimize flood-fill traversal #5595

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

📋 Pull Request Information

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

Base: main ← Head: perf/light-chunk-scratch-and-traversal


📝 Commits (2)

  • 95d06ac perf(light): reuse worker scratch buffers and optimize flood-fill traversal
  • 19de197 test(light): bound scratch queues and pin lighting against baseline algorithm

📊 Changes

1 file changed (+525 additions, -85 deletions)

View changed files

📝 crates/horizon-client-render/src/light.rs (+525 -85)

📄 Description

🤖 Opened by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally.

Closes #4385

Summary

Optimizes chunk lighting (light_chunk) by eliminating repeated heap allocation churn across worker passes and streamlining BFS queue traversal and occlusion tests:

  1. Thread-Local Scratch Buffer Reuse: Replaces per-chunk heap allocations for states (1.77 MB), sky (884 KB), block (884 KB), lowest, queues, and section unpacking buffers with a thread-local LightScratch.
  2. Linear Queue Traversal: Uses flat Vec<u32> and incrementing head indices instead of VecDeque ring-buffer wrapping math.
  3. Wavefront Early Exit: Skips querying states[q] and block_masks when light[q] >= level - 1, bypassing table lookups on already-lit neighbors.
  4. Hoisted Occlusion Mask Row: Precomputes from_row = (from >> 4) * types once per popped cell instead of recalculating it across all 6 directions.
  5. Redundant Column Check Removal: Bypasses present array checks on vertical (Y-axis) propagation steps since the column index is identical to the source node.
  6. Open Sky Fast-Path: Bypasses occlusion table checks when stepping vertically between unshaped empty air cells.

Performance & Benchmark Evidence

Measured with cargo test --release -p horizon-client-render --lib light::tests::benchmark_light_chunk -- --ignored --nocapture over 200 chunk lighting iterations on identical terrain layouts:

Pass Latency / Chunk Total Time (200 chunks) Improvement
Baseline (origin/main) 3,267.62 µs 653.52 ms Baseline
With LightScratch & Traversal Optimizations 1,371.04 µs 274.21 ms 58.0% faster (2.38x speedup)

Self-Check (pr_ready)

pr_ready (tools/pr_ready.py --quick on omarchy, against origin/main at 47a3b39fa, 4 min 57 s)

Check Result
Scope ✅ 1 files, +227 −85
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 0 s)
rustfmt ✅ (12 s)
clippy ✅ (2 min 14 s)
tests: horizon-client-render ✅ 576 passed (54 s)
doc tests ✅ 0 passed (37 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 Antigravity


🔄 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/4386 **Author:** [@elythepreciouscat](https://github.com/elythepreciouscat) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `perf/light-chunk-scratch-and-traversal` --- ### 📝 Commits (2) - [`95d06ac`](https://github.com/horizon-rust/horizon/commit/95d06ac8cdd042fa74310e858600364ee36de267) perf(light): reuse worker scratch buffers and optimize flood-fill traversal - [`19de197`](https://github.com/horizon-rust/horizon/commit/19de19792759d65580c8033eaad5ff3fe319123a) test(light): bound scratch queues and pin lighting against baseline algorithm ### 📊 Changes **1 file changed** (+525 additions, -85 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/light.rs` (+525 -85) </details> ### 📄 Description > 🤖 Opened by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally. Closes #4385 ### Summary Optimizes chunk lighting (`light_chunk`) by eliminating repeated heap allocation churn across worker passes and streamlining BFS queue traversal and occlusion tests: 1. **Thread-Local Scratch Buffer Reuse**: Replaces per-chunk heap allocations for `states` (1.77 MB), `sky` (884 KB), `block` (884 KB), `lowest`, queues, and section unpacking buffers with a thread-local `LightScratch`. 2. **Linear Queue Traversal**: Uses flat `Vec<u32>` and incrementing head indices instead of `VecDeque` ring-buffer wrapping math. 3. **Wavefront Early Exit**: Skips querying `states[q]` and `block_masks` when `light[q] >= level - 1`, bypassing table lookups on already-lit neighbors. 4. **Hoisted Occlusion Mask Row**: Precomputes `from_row = (from >> 4) * types` once per popped cell instead of recalculating it across all 6 directions. 5. **Redundant Column Check Removal**: Bypasses `present` array checks on vertical (Y-axis) propagation steps since the column index is identical to the source node. 6. **Open Sky Fast-Path**: Bypasses occlusion table checks when stepping vertically between unshaped empty air cells. ### Performance & Benchmark Evidence Measured with `cargo test --release -p horizon-client-render --lib light::tests::benchmark_light_chunk -- --ignored --nocapture` over 200 chunk lighting iterations on identical terrain layouts: | Pass | Latency / Chunk | Total Time (200 chunks) | Improvement | | :--- | :--- | :--- | :--- | | **Baseline (origin/main)** | 3,267.62 µs | 653.52 ms | Baseline | | **With `LightScratch` & Traversal Optimizations** | 1,371.04 µs | 274.21 ms | **58.0% faster (2.38x speedup)** | ### Self-Check (`pr_ready`) **pr_ready** (`tools/pr_ready.py --quick` on omarchy, against origin/main at 47a3b39fa, 4 min 57 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +227 −85 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 0 s) | | rustfmt | ✅ (12 s) | | clippy | ✅ (2 min 14 s) | | tests: horizon-client-render | ✅ 576 passed (54 s) | | doc tests | ✅ 0 passed (37 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 [Antigravity](https://deepmind.google/technologies/gemini/) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:13:40 +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#5595
No description provided.