[PR #6503] [MERGED] Mesher: ~21% less CPU per section, identical meshes #6919

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

📋 Pull Request Information

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

Base: main ← Head: perf/mesh-fill


📝 Commits (2)

  • 44b0361 Mesher: ~21% less CPU per section, same meshes
  • c33c3ac Mesher: as_chunks for the opacity rows (clippy)

📊 Changes

3 files changed (+290 additions, -72 deletions)

View changed files

📝 crates/horizon-client-render/src/mesher.rs (+131 -41)
📝 crates/horizon-client-render/src/mesher/sides.rs (+122 -31)
📝 crates/horizon-core/src/paletted.rs (+37 -0)

📄 Description

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

Part of the client performance wave (chunk section meshing). It makes the same meshes (identical bytes) with about a fifth less CPU per section, which shortens chunk loading and block-change remeshes. Stacked on #6502 (the bench that measures it).

What changed

  • Padded::fill: the section is copied row by row, and each border run of 2 or 16 cells is read from a section found once (new PalettedContainer::get_run). Before, every one of the 8,000 cells did its own chunk, section and palette lookup.
  • Hidden blocks: a block whose six neighbours are all isSolidRender is found from one opacity bit row per padded row, read from a compact per-state table. Before, it took six lookups into the ~90-byte per-state Info.
  • Biome tints: each cell's colour is kept once computed. A cell sits in the blend square of up to 25 columns, and swamp grass samples noise. The biome zoom's corner jitter is mixed once per quart cell with BiomeZoom::corner_jitter/select_corner, as generation already does.
  • sides::sort: it sorts one integer key per quad (bucket, plane, index), which gives exactly the order of the old stable sort, in buffers each thread keeps. The sorted copy no longer replaces the mesh's recycled buffer, so one allocation per mesh is gone.

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

playhorizon (x86-64 VPS, pinned to 4 of 8 vCPUs, load 30-60 from CI, so runs alternate main/PR, 2 pairs each), CPU time per section is the best of 3 rounds:

main 455b691 this PR
CPU per section with geometry (mean) 264.9 / 264.5 µs 210.5 / 209.5 µs -21%
p90 / p99 per section 314 / 670 µs 262 / 531 µs -17% / -21%
sections/s per core 9,870 12,640 +28%
vertex bytes 65.0 MB 65.0 MB same
checksum (vertices + visibility) afdcd05aec013a23 afdcd05aec013a23 identical

The parallel figure (3 threads at once) moved between 3,600 and 18,000 sections/s from run to run on this loaded machine, so it isn't a usable comparison here.

Not measured here: in-game chunk load times in perf_bench and Metal frame numbers. The Mac mini's disk was under the 25 GB floor, so I didn't build there. CPU-side numbers come from playhorizon.

Correctness

  • The bench's checksum covers every vertex byte (solid after sort_solid, translucent) and the visibility graph of 4,440 real sections: identical.
  • New unit tests: PalettedContainer::get_run reads what get reads (single, list and global palettes), and the integer-key sort orders exactly as the old stable sort over random cutout/opaque meshes with negative and signed-zero planes.
  • Not run by me yet (queued, and run by CI): the existing mesher unit tests (reuse_tests checks Padded::fill against chunk reads in every layout; visibility and leaf culling tests) and the parity harnesses (section_mesh, block_tint and translucency are the direct ones).

tools/pr_ready.py is queued behind the build slots on playhorizon (11-01 rule: 3 builds at once there). Its block will follow in a comment; CI verify runs the same fmt/clippy/tests meanwhile.

🤖 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/6503 **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-fill` --- ### 📝 Commits (2) - [`44b0361`](https://github.com/horizon-rust/horizon/commit/44b03616c1ac2a2761bae83b059c67cd260cf737) Mesher: ~21% less CPU per section, same meshes - [`c33c3ac`](https://github.com/horizon-rust/horizon/commit/c33c3acf9b64d8351eb3bfc06bdc787fe165253d) Mesher: as_chunks for the opacity rows (clippy) ### 📊 Changes **3 files changed** (+290 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/mesher.rs` (+131 -41) 📝 `crates/horizon-client-render/src/mesher/sides.rs` (+122 -31) 📝 `crates/horizon-core/src/paletted.rs` (+37 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the client performance wave (chunk section meshing). It makes the same meshes (identical bytes) with about a fifth less CPU per section, which shortens chunk loading and block-change remeshes. Stacked on #6502 (the bench that measures it). ## What changed - **`Padded::fill`**: the section is copied row by row, and each border run of 2 or 16 cells is read from a section found once (new `PalettedContainer::get_run`). Before, every one of the 8,000 cells did its own chunk, section and palette lookup. - **Hidden blocks**: a block whose six neighbours are all `isSolidRender` is found from one opacity bit row per padded row, read from a compact per-state table. Before, it took six lookups into the ~90-byte per-state `Info`. - **Biome tints**: each cell's colour is kept once computed. A cell sits in the blend square of up to 25 columns, and swamp grass samples noise. The biome zoom's corner jitter is mixed once per quart cell with `BiomeZoom::corner_jitter`/`select_corner`, as generation already does. - **`sides::sort`**: it sorts one integer key per quad (bucket, plane, index), which gives exactly the order of the old stable sort, in buffers each thread keeps. The sorted copy no longer replaces the mesh's recycled buffer, so one allocation per mesh is gone. ## A/B (`chunk_load_bench`, seed 1234, the perf_bench village, radius 8: 4,440 sections, 1,598 with geometry) playhorizon (x86-64 VPS, pinned to 4 of 8 vCPUs, load 30-60 from CI, so runs alternate main/PR, 2 pairs each), CPU time per section is the best of 3 rounds: | | main 455b691 | this PR | | |---|---|---|---| | CPU per section with geometry (mean) | 264.9 / 264.5 µs | 210.5 / 209.5 µs | **-21%** | | p90 / p99 per section | 314 / 670 µs | 262 / 531 µs | -17% / -21% | | sections/s per core | 9,870 | 12,640 | +28% | | vertex bytes | 65.0 MB | 65.0 MB | same | | checksum (vertices + visibility) | afdcd05aec013a23 | afdcd05aec013a23 | **identical** | The parallel figure (3 threads at once) moved between 3,600 and 18,000 sections/s from run to run on this loaded machine, so it isn't a usable comparison here. Not measured here: in-game chunk load times in `perf_bench` and Metal frame numbers. The Mac mini's disk was under the 25 GB floor, so I didn't build there. CPU-side numbers come from playhorizon. ## Correctness - The bench's checksum covers every vertex byte (solid after `sort_solid`, translucent) and the visibility graph of 4,440 real sections: identical. - New unit tests: `PalettedContainer::get_run` reads what `get` reads (single, list and global palettes), and the integer-key sort orders exactly as the old stable sort over random cutout/opaque meshes with negative and signed-zero planes. - Not run by me yet (queued, and run by CI): the existing mesher unit tests (`reuse_tests` checks `Padded::fill` against chunk reads in every layout; visibility and leaf culling tests) and the parity harnesses (`section_mesh`, `block_tint` and `translucency` are the direct ones). `tools/pr_ready.py` is queued behind the build slots on playhorizon (11-01 rule: 3 builds at once there). Its block will follow in a comment; CI verify runs the same fmt/clippy/tests meanwhile. 🤖 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:13 +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#6919
No description provided.