[PR #6535] [MERGED] Mesher: 15% less CPU per section again (face shortcut, bit-row VisGraph), identical meshes #6941

Closed
opened 2026-11-03 06:29:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6535
Author: @ludovic111
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/mesh-faces


📝 Commits (1)

  • 21832e9 Mesher: face visibility shortcut, call-free rounding, layer-wise fill, bit-row VisGraph

📊 Changes

4 files changed (+321 additions, -139 deletions)

View changed files

📝 crates/horizon-client-render/src/mesher.rs (+224 -126)
📝 crates/horizon-client-render/src/mesher/lighting.rs (+32 -2)
📝 crates/horizon-client-render/src/mesher/reuse_tests.rs (+1 -1)
📝 crates/horizon-client-render/src/mesher/visibility_tests.rs (+64 -10)

📄 Description

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

Part of the client performance wave (chunk section meshing). Stacked on #6503. It makes the same meshes (identical bytes) with 15% less CPU per section on top of #6503: -32% against main in total.

What changed

  • Face visibility shortcut: when the neighbour's occlusion face toward the block is the full block, the face is hidden. That is should_render_face's first test, now read from a per-state bit table before the call and its two state lookups. It's the most common answer for the faces of surface blocks.
  • Call-free rounding: TerrainVertex::new's UV f32::round and ARGB.gray's f32::floor were roundf/floorf library calls on x86-64's baseline instruction set (they showed in the profile, ~3.5%), which is what Windows and Linux players run. Replaced by exact branch-light versions, tested against the std functions over every 9,973rd/7,919th bit pattern plus the edge cases (NaN, ±inf, -0, halves, saturation). On ARM both were already single instructions.
  • Padded::fill: each chunk column's section is found once per layer, not once per row, and the runs are copied with fixed lengths.
  • VisGraph on bit rows: the flood fill fills each 16-cell row along its open runs at once (an occluded fill each way) and grows a region by sweeps over the rows it can reach. Before, it went cell by cell through a stack of 4,096. It's checked against the kept cell-by-cell reference on the existing fixtures (octants, random fills from 1% to 99%, the six-arm face pairs), on a serpentine maze, on 125 isolated pockets, and with the row fill against a cell-by-cell fill over 200,000 random rows. A carry-based row fill, tried first, was wrong when two seeds fell in one run, and the bench caught it as a hang. That case now has its own test.

Tried and dropped: compact per-state AO tables (1 byte + shade), which gave no measurable gain.

A/B (chunk_load_bench, seed 1234, the perf_bench village, radius 8: 4,440 sections, 1,598 with geometry)

playhorizon (x86-64 VPS, 4 of 8 vCPUs pinned, load ~18-24), alternating runs, best of 3 rounds per section:

main 455b691 #6503 this PR vs #6503 vs main
CPU per section with geometry 260.8 / 259.5 µs 209.6 / 205.3 µs 177.7 / 176.1 µs -15% -32%
p90 / p99 309 / 656 µs 260 / 534 µs 219 / 471 µs -16% / -12% -29% / -28%
sections/s per core 10,050 12,790 15,020 +17% +49%
checksum (vertices + visibility) afdcd05aec013a23 same same identical identical

Not measured: in-game perf_bench chunk loads and Metal frames. The Mac mini's disk was under the 25 GB floor.

tools/pr_ready.py: queued behind playhorizon's build slots; CI verify runs the same checks. The block will follow in a comment.

🤖 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/6535 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/mesh-faces` --- ### 📝 Commits (1) - [`21832e9`](https://github.com/horizon-rust/horizon/commit/21832e9390ceeedefeab3029b5376cb6377491ee) Mesher: face visibility shortcut, call-free rounding, layer-wise fill, bit-row VisGraph ### 📊 Changes **4 files changed** (+321 additions, -139 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/mesher.rs` (+224 -126) 📝 `crates/horizon-client-render/src/mesher/lighting.rs` (+32 -2) 📝 `crates/horizon-client-render/src/mesher/reuse_tests.rs` (+1 -1) 📝 `crates/horizon-client-render/src/mesher/visibility_tests.rs` (+64 -10) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the client performance wave (chunk section meshing). Stacked on #6503. It makes the same meshes (identical bytes) with 15% less CPU per section on top of #6503: **-32% against main** in total. ## What changed - **Face visibility shortcut**: when the neighbour's occlusion face toward the block is the full block, the face is hidden. That is `should_render_face`'s first test, now read from a per-state bit table before the call and its two state lookups. It's the most common answer for the faces of surface blocks. - **Call-free rounding**: `TerrainVertex::new`'s UV `f32::round` and `ARGB.gray`'s `f32::floor` were `roundf`/`floorf` library calls on x86-64's baseline instruction set (they showed in the profile, ~3.5%), which is what Windows and Linux players run. Replaced by exact branch-light versions, tested against the std functions over every 9,973rd/7,919th bit pattern plus the edge cases (NaN, ±inf, -0, halves, saturation). On ARM both were already single instructions. - **`Padded::fill`**: each chunk column's section is found once per layer, not once per row, and the runs are copied with fixed lengths. - **VisGraph on bit rows**: the flood fill fills each 16-cell row along its open runs at once (an occluded fill each way) and grows a region by sweeps over the rows it can reach. Before, it went cell by cell through a stack of 4,096. It's checked against the kept cell-by-cell reference on the existing fixtures (octants, random fills from 1% to 99%, the six-arm face pairs), on a serpentine maze, on 125 isolated pockets, and with the row fill against a cell-by-cell fill over 200,000 random rows. A carry-based row fill, tried first, was wrong when two seeds fell in one run, and the bench caught it as a hang. That case now has its own test. Tried and dropped: compact per-state AO tables (1 byte + shade), which gave no measurable gain. ## A/B (`chunk_load_bench`, seed 1234, the perf_bench village, radius 8: 4,440 sections, 1,598 with geometry) playhorizon (x86-64 VPS, 4 of 8 vCPUs pinned, load ~18-24), alternating runs, best of 3 rounds per section: | | main 455b691 | #6503 | this PR | vs #6503 | vs main | |---|---|---|---|---|---| | CPU per section with geometry | 260.8 / 259.5 µs | 209.6 / 205.3 µs | 177.7 / 176.1 µs | -15% | **-32%** | | p90 / p99 | 309 / 656 µs | 260 / 534 µs | 219 / 471 µs | -16% / -12% | -29% / -28% | | sections/s per core | 10,050 | 12,790 | 15,020 | +17% | **+49%** | | checksum (vertices + visibility) | afdcd05aec013a23 | same | same | identical | identical | Not measured: in-game `perf_bench` chunk loads and Metal frames. The Mac mini's disk was under the 25 GB floor. `tools/pr_ready.py`: queued behind playhorizon's build slots; CI verify runs the same checks. The block will follow in a comment. 🤖 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-03 06:29:43 +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#6941
No description provided.