[GH-ISSUE #4385] Chunk lighting: reuse worker scratch buffers and optimize flood-fill traversal #1303

Closed
opened 2026-11-02 15:45:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @elythepreciouscat on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4385

Originally assigned to: @elythepreciouscat on GitHub.

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

Problem

Chunk lighting (light_chunk) is invoked across chunk generation, loading, and worker streaming. In its current implementation:

  1. Per-chunk allocation churn: Every chunk lighting job allocates new states (1.77 MB), sky (884 KB), block (884 KB), VecDeque queues, and section unpacking buffers on the heap, creating high memory allocator and cache line churn under fast world streaming.
  2. Ring buffer overhead: VecDeque::pop_front incurs non-linear ring-buffer wrapping math on every queue element popped.
  3. Flood-fill traversal redundancy:
    • states[q] and packed_blocked are queried for every neighbor even when light[q] is already at or above level - 1, where a light increase is impossible.
    • Neighbor direction occlusion masks recompute (from >> 4) as usize * types for all 6 directions instead of hoisting the row offset.
    • Column present checks are performed for vertical neighbors (Y-axis) where the column coordinate is invariant and guaranteed present.
    • Open-sky vertical raycasting evaluates occlusion for adjacent air blocks where both cells are unshaped and empty.

Proposed Solution

  1. Introduce thread-local reusable scratch storage (LightScratch) for chunk lighting worker jobs, eliminating heap allocations for states, sky, block, queues, and section unpacking buffers.
  2. Replace VecDeque with a linear Vec<u32> and incrementing head index for BFS queue propagation.
  3. Fast-exit wavefront traversal when light[q] >= level - 1, avoiding states reads and occlusion mask lookups on already-lit nodes.
  4. Hoist from_row occlusion table lookups per popped cell and bypass redundant present checks on Y-axis steps.
  5. Fast-path open sky ray stepping for air-to-air boundaries.

🤖 Generated with Antigravity

Originally created by @elythepreciouscat on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4385 Originally assigned to: @elythepreciouscat on GitHub. > 🤖 Filed by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally. ### Problem Chunk lighting (`light_chunk`) is invoked across chunk generation, loading, and worker streaming. In its current implementation: 1. **Per-chunk allocation churn**: Every chunk lighting job allocates new `states` (1.77 MB), `sky` (884 KB), `block` (884 KB), `VecDeque` queues, and section unpacking buffers on the heap, creating high memory allocator and cache line churn under fast world streaming. 2. **Ring buffer overhead**: `VecDeque::pop_front` incurs non-linear ring-buffer wrapping math on every queue element popped. 3. **Flood-fill traversal redundancy**: - `states[q]` and `packed_blocked` are queried for every neighbor even when `light[q]` is already at or above `level - 1`, where a light increase is impossible. - Neighbor direction occlusion masks recompute `(from >> 4) as usize * types` for all 6 directions instead of hoisting the row offset. - Column present checks are performed for vertical neighbors (Y-axis) where the column coordinate is invariant and guaranteed present. - Open-sky vertical raycasting evaluates occlusion for adjacent air blocks where both cells are unshaped and empty. ### Proposed Solution 1. Introduce thread-local reusable scratch storage (`LightScratch`) for chunk lighting worker jobs, eliminating heap allocations for `states`, `sky`, `block`, queues, and section unpacking buffers. 2. Replace `VecDeque` with a linear `Vec<u32>` and incrementing head index for BFS queue propagation. 3. Fast-exit wavefront traversal when `light[q] >= level - 1`, avoiding `states` reads and occlusion mask lookups on already-lit nodes. 4. Hoist `from_row` occlusion table lookups per popped cell and bypass redundant `present` checks on Y-axis steps. 5. Fast-path open sky ray stepping for air-to-air boundaries. 🤖 Generated with [Antigravity](https://deepmind.google/technologies/gemini/)
Author
Owner

@elythepreciouscat commented on GitHub (Oct 30, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6523209694 --> @elythepreciouscat commented on GitHub (Oct 30, 2026): 🤖 Agent: /claim
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#1303
No description provided.