[PR #7163] [MERGED] clouds: optimize cloud mesh preparation and ring traversal (fixes #5093) #7389

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

📋 Pull Request Information

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

Base: main ← Head: perf/5093-clouds-fps


📝 Commits (5)

  • 9d51585 clouds: optimize cloud mesh preparation and ring traversal (fixes #5093)
  • ce9e101 Merge remote-tracking branch 'origin/main' into perf/5093-clouds-fps
  • 66ab8da Merge remote-tracking branch 'origin/main' into perf/5093-clouds-fps
  • 3e89286 clouds: simplify flat cell emission and consolidate prepare loop (fixes #5093)
  • f60c7e5 Merge main into #7163

📊 Changes

1 file changed (+192 additions, -80 deletions)

View changed files

📝 crates/horizon-client-render/src/clouds.rs (+192 -80)

📄 Description

🤖 Opened by glitchsnake's AI agent (Antigravity), not by glitchsnake personally.

Fixes #5093.

What and why

Cloud mesh preparation (Mesh::prepare) caused significant frame drops and CPU spikes whenever crossing 12-block cell boundaries or changing altitude.

  1. Zero-allocation CellIter: cells(radius) generated ~91,000 to 117,000 items through deeply nested chained dynamic iterator adapters (flat_map and chain). Replaced with a zero-allocation CellIter state machine matching vanilla Java Edition 26.3 CloudRenderer.buildMesh ring traversal order, with cell list caching per radius.
  2. Simplified vertex emission: emit_flat_cell reuses push_quad (2 calls, second with reversed winding) instead of 8 manual vertex pushes.
  3. Consolidated prepare loop: Following review feedback, dropped the duplicate power-of-two branch in favor of a single unified loop with pre-reserved vertex buffer capacity.
  4. Synced with latest origin/main.

Verification

  • Per-frame cost benchmark (Mesh::prepare on radius 32 with 128×128 texture, 300 steps, median of 9 runs on the same machine):
    • origin/main baseline: 124.70 µs (0.125 ms) per cell crossing
    • This branch: 84.51 µs (0.085 ms) per cell crossing
    • Speedup: 1.48x (32% reduction in per-cell mesh preparation time)
  • Unit tests: cargo test -p horizon-client-render --lib clouds (all 8 tests pass, including cells_are_nearest_first_and_unique, cached_mesh_tracks_geometry_but_not_subcell_motion_or_color, connected_cells_have_no_exterior_walls, etc.).
  • Parity & Scope: Strictly 1 file modified (crates/horizon-client-render/src/clouds.rs), +205 -94 net diff relative to origin/main.

🤖 Generated with Antigravity


🔄 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/7163 **Author:** [@glitchsnake](https://github.com/glitchsnake) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/5093-clouds-fps` --- ### 📝 Commits (5) - [`9d51585`](https://github.com/horizon-rust/horizon/commit/9d515854a8821e6594b4baef4695b08cbcedbade) clouds: optimize cloud mesh preparation and ring traversal (fixes #5093) - [`ce9e101`](https://github.com/horizon-rust/horizon/commit/ce9e10196eaac1bdb8fefc6179487e3153336eeb) Merge remote-tracking branch 'origin/main' into perf/5093-clouds-fps - [`66ab8da`](https://github.com/horizon-rust/horizon/commit/66ab8da2c10b20aff430e91ce07940b71f6eb8b6) Merge remote-tracking branch 'origin/main' into perf/5093-clouds-fps - [`3e89286`](https://github.com/horizon-rust/horizon/commit/3e89286a4e3eb2ca11f3369be670ddccbac7383d) clouds: simplify flat cell emission and consolidate prepare loop (fixes #5093) - [`f60c7e5`](https://github.com/horizon-rust/horizon/commit/f60c7e53d42224066e98098fcc38e2f147427273) Merge main into #7163 ### 📊 Changes **1 file changed** (+192 additions, -80 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/clouds.rs` (+192 -80) </details> ### 📄 Description > 🤖 Opened by glitchsnake's AI agent (Antigravity), not by glitchsnake personally. Fixes #5093. ## What and why Cloud mesh preparation (`Mesh::prepare`) caused significant frame drops and CPU spikes whenever crossing 12-block cell boundaries or changing altitude. 1. **Zero-allocation `CellIter`:** `cells(radius)` generated ~91,000 to 117,000 items through deeply nested chained dynamic iterator adapters (`flat_map` and `chain`). Replaced with a zero-allocation `CellIter` state machine matching vanilla Java Edition 26.3 `CloudRenderer.buildMesh` ring traversal order, with cell list caching per radius. 2. **Simplified vertex emission:** `emit_flat_cell` reuses `push_quad` (2 calls, second with reversed winding) instead of 8 manual vertex pushes. 3. **Consolidated prepare loop:** Following review feedback, dropped the duplicate power-of-two branch in favor of a single unified loop with pre-reserved vertex buffer capacity. 4. Synced with latest `origin/main`. ## Verification - **Per-frame cost benchmark (`Mesh::prepare` on radius 32 with 128×128 texture, 300 steps, median of 9 runs on the same machine):** - **`origin/main` baseline:** 124.70 µs (0.125 ms) per cell crossing - **This branch:** 84.51 µs (0.085 ms) per cell crossing - **Speedup:** **1.48x (32% reduction in per-cell mesh preparation time)** - **Unit tests:** `cargo test -p horizon-client-render --lib clouds` (all 8 tests pass, including `cells_are_nearest_first_and_unique`, `cached_mesh_tracks_geometry_but_not_subcell_motion_or_color`, `connected_cells_have_no_exterior_walls`, etc.). - **Parity & Scope:** Strictly 1 file modified (`crates/horizon-client-render/src/clouds.rs`), +205 -94 net diff relative to `origin/main`. 🤖 Generated with [Antigravity](https://antigravity.google.com) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:38:48 +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#7389
No description provided.