[PR #781] [MERGED] light: pack the flood fill and precompute neighbour blocking #2805

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

📋 Pull Request Information

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

Base: main ← Head: t3code/2a9d6cd1


📝 Commits (1)

  • 9004019 light: pack the flood fill and precompute neighbour blocking

📊 Changes

1 file changed (+143 additions, -35 deletions)

View changed files

📝 crates/horizon-client/src/light.rs (+143 -35)

📄 Description

What and why

light_chunk's sky and block flood fills read LightTables::cells for every neighbour, and together with the fill loop they dominated lighting cost (the perf brief sampled light::light_chunk at 13.3% of worker samples, with the lighting queue peaking at 128). This makes the two spreads and the fill operate on a compact per-cell representation instead of random lookups into the 570 KB state table:

  • each state gets a packed info word (emission << 16 | type << 4 | dampening); the cell array becomes u16 and the floods never touch cells;
  • blocked becomes a precomputed per-configuration bitmask (54 distinct configurations here, so a 54 × 54 table);
  • neighbours are stepped by linear offset with an axis bounds check, so the "no wrap" test is a comparison rather than coordinate arithmetic, and present is a precomputed per-column table.

Measured on a 1156-column block (render-distance ~12): light_chunk 1.81 → 1.31 ms/col, ~28% faster, identical checksum. chunk_bench drops from ~1.98 to ~1.49 ms/col under the same load.

No player-visible change: light values are identical.

Vanilla reference

Follows the same vanilla code as before — LightEngine.shapeOccludes, ChunkSkyLightSources.isEdgeOccluded, and the shape occlusion tables from occlusion.nbt — and only caches their per-configuration results. Checked by tools/test_light_parity.py against the vanilla 26.3 server:

1179648 values compared: 0 sky and 0 block light values differ
100 edits: 0 light values differ from a full relight
light parity ok

Self-check

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at af3e75fec, 2 min 34 s)

Check Result
Scope ✅ 1 file, +143 −35
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (11 s)
clippy ✅ (6 s)
tests: horizon-client ✅ 926 passed (2 min 15 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ affected harnesses, to run in CI (--quick)

The light parity harness was also run locally (full, not --quick) and passed as shown above.


🔄 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/781 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `t3code/2a9d6cd1` --- ### 📝 Commits (1) - [`9004019`](https://github.com/horizon-rust/horizon/commit/90040198007acf74aa60581004c1fb4536485a38) light: pack the flood fill and precompute neighbour blocking ### 📊 Changes **1 file changed** (+143 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/light.rs` (+143 -35) </details> ### 📄 Description ## What and why `light_chunk`'s sky and block flood fills read `LightTables::cells` for every neighbour, and together with the fill loop they dominated lighting cost (the perf brief sampled `light::light_chunk` at 13.3% of worker samples, with the lighting queue peaking at 128). This makes the two spreads and the fill operate on a compact per-cell representation instead of random lookups into the 570 KB state table: - each state gets a packed `info` word (`emission << 16 | type << 4 | dampening`); the cell array becomes `u16` and the floods never touch `cells`; - `blocked` becomes a precomputed per-configuration bitmask (`54` distinct configurations here, so a `54 × 54` table); - neighbours are stepped by linear offset with an axis bounds check, so the "no wrap" test is a comparison rather than coordinate arithmetic, and `present` is a precomputed per-column table. Measured on a 1156-column block (render-distance ~12): **`light_chunk` 1.81 → 1.31 ms/col, ~28% faster**, identical checksum. `chunk_bench` drops from ~1.98 to ~1.49 ms/col under the same load. No player-visible change: light values are identical. ## Vanilla reference Follows the same vanilla code as before — `LightEngine.shapeOccludes`, `ChunkSkyLightSources.isEdgeOccluded`, and the shape occlusion tables from `occlusion.nbt` — and only caches their per-configuration results. Checked by `tools/test_light_parity.py` against the vanilla 26.3 server: ``` 1179648 values compared: 0 sky and 0 block light values differ 100 edits: 0 light values differ from a full relight light parity ok ``` ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at af3e75fec, 2 min 34 s) | Check | Result | | --- | --- | | Scope | ✅ 1 file, +143 −35 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (11 s) | | clippy | ✅ (6 s) | | tests: horizon-client | ✅ 926 passed (2 min 15 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ affected harnesses, to run in CI (--quick) | The light parity harness was also run locally (full, not `--quick`) and passed as shown above. --- <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:11 +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#2805
No description provided.