[PR #243] [MERGED] perf(mesher): short-circuit section visibility flood fills #2433

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

📋 Pull Request Information

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

Base: main ← Head: perf/visibility-shortcuts-20261014


📝 Commits (1)

  • 90f84ac perf(mesher): short-circuit section visibility flood fills

📊 Changes

3 files changed (+388 additions, -9 deletions)

View changed files

📝 crates/horizon-client/src/mesher.rs (+32 -9)
➕ crates/horizon-client/src/mesher/visibility_tests.rs (+279 -0)
➕ docs/visibility-benchmark.md (+77 -0)

📄 Description

Section visibility flood-fills every open region even after all 36 face connections have been found. This change returns immediately when a connected region touches all six faces, or completed regions collectively supply every connection. It also resolves opacity once into the visited map and returns directly for fully open/closed sections. All face-pair flags, including diagonal self-visibility, are preserved.

The visited map moves from a 4 KiB heap allocation to 4 KiB on the worker stack. Mixed sections retain the growable traversal stack; no persistent storage is added. Scope is the section connectivity helper, its tests, and benchmark documentation (optimization 13).

Validation

Passed with CARGO_INCREMENTAL=0 and shared CARGO_TARGET_DIR=/home/bob/Documents/horizon/target:

  • cargo test -p horizon-client --lib --profile fast mesher::visibility_tests: 2 passed; opt-in benchmark ignored.
  • cargo test -p horizon-client --lib --profile fast mesher::visibility_tests::visibility_benchmark -- --ignored --exact --nocapture --test-threads=1: 1 passed.
  • cargo fmt --all -- --check.
  • cargo clippy -p horizon-client --lib --tests --profile fast -- -D warnings (also checks compilation of relevant targets).
  • Final diff whitespace check; clean worktree after commit.

Correctness compares an exact copy of the original helper from main 73a019967e9665c6b96332988c13cb66679d8477 against the production helper: 14 fixtures, 256 octant combinations, 224 random sections, all 64 touched-face subsets, disconnected corners, and three disconnected regions whose union supplies all 36 flags. Full parity suite and workspace-wide Clippy were not run.

Benchmark

AMD Ryzen 5 5600X, Linux 7.2.8-zen1-2-zen, x86_64, rustc 1.99.0/LLVM 23.1.1; Cargo fast (opt-level 3, no LTO, 16 codegen units), incremental disabled. Measured 2026-10-15. The benchmark calls the actual private production helper with full-layout Padded/Info, against the exact original implementation, on identical inputs. Outputs must match. Each case uses 200 warmup calls per implementation and 11 samples × 1000 calls, alternating order and using black_box for inputs/results. The table reports median nanoseconds per 4096-cell section; fixture/state-table construction is excluded. Shared-target builds were serialized by Cargo's build-directory lock during measurement.

Case Opaque cells Before ns After ns Speedup
Fully open 0 27,019.3 2,691.6 10.04×
Fully closed 4,096 4,823.5 2,788.7 1.73×
Terrain lower half 2,048 15,274.3 14,258.1 1.07×
Dividing wall 256 25,006.6 24,107.5 1.04×
Sealed cavity 1,352 19,953.7 17,591.7 1.13×
Disconnected all pairs 3,586 7,915.9 6,301.4 1.26×
Checkerboard 2,048 26,846.5 18,697.4 1.44×
Six-face tunnel 4,050 5,236.7 2,972.3 1.76×
Open with sealed cavity 296 26,140.3 9,688.8 2.70×
Random 1% opaque 38 27,657.9 9,061.1 3.05×
Random 25% opaque 1,043 24,931.4 7,722.5 3.23×
Random 50% opaque 2,050 19,811.5 5,754.7 3.44×
Random 75% opaque 3,053 13,598.2 10,474.1 1.30×
Random 99% opaque 4,064 5,330.7 4,023.7 1.32×

No measured case regressed; the 4–7% wall/terrain gains are small and susceptible to noise. No prepared section/assets fixtures were found in a bounded project/cache search, so these are deterministic synthetic production-sized sections with a two-block border and four state IDs (two of each opacity). Real-world section frequencies are unknown; no aggregate claim is made. The mesher already skips uniform all-air sections, so that benchmark describes the helper and other fully non-opaque sections. These are isolated connectivity improvements, without an overall startup, meshing, or FPS claim.

The reproducible benchmark and complete results are committed in docs/visibility-benchmark.md and crates/horizon-client/src/mesher/visibility_tests.rs.


🔄 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/243 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/visibility-shortcuts-20261014` --- ### 📝 Commits (1) - [`90f84ac`](https://github.com/horizon-rust/horizon/commit/90f84ac10dd384cefe7a7a70501366a4be3a5697) perf(mesher): short-circuit section visibility flood fills ### 📊 Changes **3 files changed** (+388 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mesher.rs` (+32 -9) ➕ `crates/horizon-client/src/mesher/visibility_tests.rs` (+279 -0) ➕ `docs/visibility-benchmark.md` (+77 -0) </details> ### 📄 Description Section visibility flood-fills every open region even after all 36 face connections have been found. This change returns immediately when a connected region touches all six faces, or completed regions collectively supply every connection. It also resolves opacity once into the visited map and returns directly for fully open/closed sections. All face-pair flags, including diagonal self-visibility, are preserved. The visited map moves from a 4 KiB heap allocation to 4 KiB on the worker stack. Mixed sections retain the growable traversal stack; no persistent storage is added. Scope is the section connectivity helper, its tests, and benchmark documentation (optimization 13). ## Validation Passed with `CARGO_INCREMENTAL=0` and shared `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target`: - `cargo test -p horizon-client --lib --profile fast mesher::visibility_tests`: 2 passed; opt-in benchmark ignored. - `cargo test -p horizon-client --lib --profile fast mesher::visibility_tests::visibility_benchmark -- --ignored --exact --nocapture --test-threads=1`: 1 passed. - `cargo fmt --all -- --check`. - `cargo clippy -p horizon-client --lib --tests --profile fast -- -D warnings` (also checks compilation of relevant targets). - Final diff whitespace check; clean worktree after commit. Correctness compares an exact copy of the original helper from main `73a019967e9665c6b96332988c13cb66679d8477` against the production helper: 14 fixtures, 256 octant combinations, 224 random sections, all 64 touched-face subsets, disconnected corners, and three disconnected regions whose union supplies all 36 flags. Full parity suite and workspace-wide Clippy were not run. ## Benchmark AMD Ryzen 5 5600X, Linux 7.2.8-zen1-2-zen, x86_64, rustc 1.99.0/LLVM 23.1.1; Cargo `fast` (opt-level 3, no LTO, 16 codegen units), incremental disabled. Measured 2026-10-15. The benchmark calls the actual private production helper with full-layout `Padded`/`Info`, against the exact original implementation, on identical inputs. Outputs must match. Each case uses 200 warmup calls per implementation and 11 samples × 1000 calls, alternating order and using `black_box` for inputs/results. The table reports median nanoseconds per 4096-cell section; fixture/state-table construction is excluded. Shared-target builds were serialized by Cargo's build-directory lock during measurement. | Case | Opaque cells | Before ns | After ns | Speedup | | --- | ---: | ---: | ---: | ---: | | Fully open | 0 | 27,019.3 | 2,691.6 | 10.04× | | Fully closed | 4,096 | 4,823.5 | 2,788.7 | 1.73× | | Terrain lower half | 2,048 | 15,274.3 | 14,258.1 | 1.07× | | Dividing wall | 256 | 25,006.6 | 24,107.5 | 1.04× | | Sealed cavity | 1,352 | 19,953.7 | 17,591.7 | 1.13× | | Disconnected all pairs | 3,586 | 7,915.9 | 6,301.4 | 1.26× | | Checkerboard | 2,048 | 26,846.5 | 18,697.4 | 1.44× | | Six-face tunnel | 4,050 | 5,236.7 | 2,972.3 | 1.76× | | Open with sealed cavity | 296 | 26,140.3 | 9,688.8 | 2.70× | | Random 1% opaque | 38 | 27,657.9 | 9,061.1 | 3.05× | | Random 25% opaque | 1,043 | 24,931.4 | 7,722.5 | 3.23× | | Random 50% opaque | 2,050 | 19,811.5 | 5,754.7 | 3.44× | | Random 75% opaque | 3,053 | 13,598.2 | 10,474.1 | 1.30× | | Random 99% opaque | 4,064 | 5,330.7 | 4,023.7 | 1.32× | No measured case regressed; the 4–7% wall/terrain gains are small and susceptible to noise. No prepared section/assets fixtures were found in a bounded project/cache search, so these are deterministic synthetic production-sized sections with a two-block border and four state IDs (two of each opacity). Real-world section frequencies are unknown; no aggregate claim is made. The mesher already skips uniform all-air sections, so that benchmark describes the helper and other fully non-opaque sections. These are isolated connectivity improvements, without an overall startup, meshing, or FPS claim. The reproducible benchmark and complete results are committed in `docs/visibility-benchmark.md` and `crates/horizon-client/src/mesher/visibility_tests.rs`. --- <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:04 +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#2433
No description provided.