[PR #2927] [MERGED] Worldgen: cut aquifer, carver and fill costs on the terrain stage #4686

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2927
Author: @hectoreccles
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: perf/terrain-rustgen-ports


📝 Commits (10+)

  • 7671219 Worldgen: skip the aquifer for solid and high air blocks in the fill
  • 0f596d9 Worldgen: one material worker per carving pass
  • e319dd5 Worldgen: resolve each surface column once into a reused buffer
  • e71f98a Worldgen: write positive-density fill runs through the section once
  • 01d0170 Worldgen: keep the skipped aquifer decisions' pending fluid flag
  • fb769e5 Worldgen: rustfmt the terrain performance changes
  • 20d7d11 Merge branch 'ludovic111:main' into perf/terrain-rustgen-ports
  • 44448d9 Merge #2706 into #2927: the unchanged-block skip reads the column cache
  • 8bb23aa Merge remote-tracking branch 'origin/main' into pt3/2927
  • 5e6bed2 Merge main into this branch; the column fill uses the palette scan

📊 Changes

7 files changed (+365 additions, -54 deletions)

View changed files

📝 crates/horizon-world/src/chunk.rs (+66 -0)
📝 crates/horizon-world/src/worldgen/aquifer/noise_based.rs (+16 -0)
📝 crates/horizon-world/src/worldgen/carving.rs (+35 -14)
📝 crates/horizon-world/src/worldgen/material_condition/density.rs (+30 -0)
📝 crates/horizon-world/src/worldgen/material_condition/rule.rs (+7 -0)
📝 crates/horizon-world/src/worldgen/material_stage.rs (+99 -36)
📝 crates/horizon-world/src/worldgen/terrain.rs (+112 -4)

📄 Description

🤖 Opened by hectoreccles's AI agent (OpenCode, DeepSeek V4.1 Flash), not by hectoreccles himself.

What and why

A release-profile samply profile showed four avoidable per-block costs in the terrain fill, carvers and surface step. This PR fixes them, measures each change on a Mac, and keeps only the ones that win. It also fixes the one parity difference the fill probe found.

Changes

  1. 7671219f1 — The fill decides positive density and air above the aquifer's skip/fluid level itself. TerrainAquifer gained air_above_y; 01d01708 reproduces the skipped calls' pending-update flag so parity is exact. The aquifer no longer sees most of its ~98k calls per chunk.
  2. 0f596d9e3 — One MaterialConditions per carving pass; the top-material rule is compiled once and only the 1×1×1 density bindings move per restored dirt cell.
  3. e319dd578 — Each surface column is resolved once into a reused block-id buffer, with write-through. The stone-depth look-behind no longer re-decodes paletted sections.
  4. e71f98add — Positive-density fill runs are written through the section once: one palette lookup, non-air counts in bulk, heightmap at the run top. Cells whose density is entirely positive are entirely the default block, so the run write is exact.
  5. 01d01708 — The parity fix above: both skipped paths used to clear the aquifer's pending fluid update; the fill now does that without the call.
  6. fb769e55e — rustfmt.

Benchmarks (Mac)

Machine: MacBook Pro (Mac16,5), Apple M4 Max, 14 cores (10 performance + 4 efficiency), 36 GB, macOS. Release profile (thin LTO, codegen-units 1). horizon-world example chunkgen_bench, seed 0, 32×32 chunks at (0,0), --warmup, --no-map, 1 and 13 threads. Baseline and candidate interleaved, min and median of 7 runs. The benchmark stops at FEATURES (no lighting). Unrelated desktop load was present, so small individual deltas are within noise; the cumulative numbers and stage medians are the reliable ones.

Cumulative (main → this PR):

Run Baseline PR Improvement
terrain, 1 thread 4.237 s 3.828 s +9.7%
terrain + 900 decorations, 1 thread 4.987 s 4.580 s +8.2%
terrain, 13 threads 0.674 s 0.644 s +4.5%
terrain + decoration, 13 threads 0.770 s 0.741 s +3.8%

Per-stage medians, 1 thread: noise 1.89 → 1.58 ms, carvers 0.44 → 0.39 ms, surface 1.41 → 1.38 ms. 13 threads: noise 2.49 → 2.09 ms, carvers 0.59 → 0.48 ms, surface 3.87 → 4.02 ms (within noise). Decoration is unchanged.

Per change (1 thread, min): aquifer skip +5.1%; carver worker +0.6% end-to-end with carvers −9% (13 threads: carvers −21%); surface column cache +2.6%; solid fill runs +4.4%.

Reproduce:

cargo build --release -p horizon-world --example chunkgen_bench
target/release/examples/chunkgen_bench .local/horizon-client/26.3 \
  --seed 0 --size 32 --center 16 16 --threads 1 --warmup --json --no-map

The A/B script used here (interleaved min/median plus snapshot hashes) lives in the worktree at target/bench/ab.py; it is a local harness and is not part of the PR.

Parity

  • python3 tools/test_terrain_parity.py: 7,950,873 output lines per side match (client and server).
  • python3 tools/test_material_stage_parity.py: 6,733,382 output lines per side match.
  • Snapshot hashes of 256 chunks (terrain and decorated) are identical.

Local checks

  • cargo fmt --check passed.
  • cargo clippy -p horizon-world --all-targets -- -D warnings passed.
  • cargo test -p horizon-world --lib: 177 passed, 1 ignored.
  • python3 tools/test_terrain_parity.py: 7,950,873 output lines per side match.
  • python3 tools/test_material_stage_parity.py: 6,733,382 output lines per side match.

🤖 Generated with OpenCode


🔄 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/2927 **Author:** [@hectoreccles](https://github.com/hectoreccles) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `perf/terrain-rustgen-ports` --- ### 📝 Commits (10+) - [`7671219`](https://github.com/horizon-rust/horizon/commit/7671219f1aa548239b9fa50223cb450ae165781c) Worldgen: skip the aquifer for solid and high air blocks in the fill - [`0f596d9`](https://github.com/horizon-rust/horizon/commit/0f596d9e3c7f420f7ef54096b3d32b25c23147eb) Worldgen: one material worker per carving pass - [`e319dd5`](https://github.com/horizon-rust/horizon/commit/e319dd578f2adce4f762f5c28320db83dede198e) Worldgen: resolve each surface column once into a reused buffer - [`e71f98a`](https://github.com/horizon-rust/horizon/commit/e71f98addea9446de8c9bfa5e183e221f1f6e45a) Worldgen: write positive-density fill runs through the section once - [`01d0170`](https://github.com/horizon-rust/horizon/commit/01d0170821f19dcc1f85bd27151cd254778e2b3e) Worldgen: keep the skipped aquifer decisions' pending fluid flag - [`fb769e5`](https://github.com/horizon-rust/horizon/commit/fb769e55e0c219ea28c09d006e3652fd9493a05e) Worldgen: rustfmt the terrain performance changes - [`20d7d11`](https://github.com/horizon-rust/horizon/commit/20d7d111e5cd960898c89a62848005889fb54f1d) Merge branch 'ludovic111:main' into perf/terrain-rustgen-ports - [`44448d9`](https://github.com/horizon-rust/horizon/commit/44448d941f01df6f2e06ebd6f5639579c69f3c2c) Merge #2706 into #2927: the unchanged-block skip reads the column cache - [`8bb23aa`](https://github.com/horizon-rust/horizon/commit/8bb23aa1f78af1699473a18391d3639e5ab9f497) Merge remote-tracking branch 'origin/main' into pt3/2927 - [`5e6bed2`](https://github.com/horizon-rust/horizon/commit/5e6bed2e427af05f7a3feb58a413c33f3efb0837) Merge main into this branch; the column fill uses the palette scan ### 📊 Changes **7 files changed** (+365 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/chunk.rs` (+66 -0) 📝 `crates/horizon-world/src/worldgen/aquifer/noise_based.rs` (+16 -0) 📝 `crates/horizon-world/src/worldgen/carving.rs` (+35 -14) 📝 `crates/horizon-world/src/worldgen/material_condition/density.rs` (+30 -0) 📝 `crates/horizon-world/src/worldgen/material_condition/rule.rs` (+7 -0) 📝 `crates/horizon-world/src/worldgen/material_stage.rs` (+99 -36) 📝 `crates/horizon-world/src/worldgen/terrain.rs` (+112 -4) </details> ### 📄 Description > 🤖 Opened by hectoreccles's AI agent (OpenCode, DeepSeek V4.1 Flash), not by hectoreccles himself. ## What and why A release-profile `samply` profile showed four avoidable per-block costs in the terrain fill, carvers and surface step. This PR fixes them, measures each change on a Mac, and keeps only the ones that win. It also fixes the one parity difference the fill probe found. ## Changes 1. `7671219f1` — The fill decides positive density and air above the aquifer's skip/fluid level itself. `TerrainAquifer` gained `air_above_y`; `01d01708` reproduces the skipped calls' pending-update flag so parity is exact. The aquifer no longer sees most of its ~98k calls per chunk. 2. `0f596d9e3` — One `MaterialConditions` per carving pass; the top-material rule is compiled once and only the 1×1×1 density bindings move per restored dirt cell. 3. `e319dd578` — Each surface column is resolved once into a reused block-id buffer, with write-through. The stone-depth look-behind no longer re-decodes paletted sections. 4. `e71f98add` — Positive-density fill runs are written through the section once: one palette lookup, non-air counts in bulk, heightmap at the run top. Cells whose density is entirely positive are entirely the default block, so the run write is exact. 5. `01d01708` — The parity fix above: both skipped paths used to clear the aquifer's pending fluid update; the fill now does that without the call. 6. `fb769e55e` — rustfmt. ## Benchmarks (Mac) Machine: MacBook Pro (Mac16,5), Apple M4 Max, 14 cores (10 performance + 4 efficiency), 36 GB, macOS. Release profile (thin LTO, codegen-units 1). `horizon-world` example `chunkgen_bench`, seed 0, 32×32 chunks at (0,0), `--warmup`, `--no-map`, 1 and 13 threads. Baseline and candidate interleaved, min and median of 7 runs. The benchmark stops at FEATURES (no lighting). Unrelated desktop load was present, so small individual deltas are within noise; the cumulative numbers and stage medians are the reliable ones. Cumulative (main → this PR): | Run | Baseline | PR | Improvement | |---|---:|---:|---:| | terrain, 1 thread | 4.237 s | 3.828 s | **+9.7%** | | terrain + 900 decorations, 1 thread | 4.987 s | 4.580 s | **+8.2%** | | terrain, 13 threads | 0.674 s | 0.644 s | **+4.5%** | | terrain + decoration, 13 threads | 0.770 s | 0.741 s | **+3.8%** | Per-stage medians, 1 thread: noise **1.89 → 1.58 ms**, carvers **0.44 → 0.39 ms**, surface **1.41 → 1.38 ms**. 13 threads: noise **2.49 → 2.09 ms**, carvers **0.59 → 0.48 ms**, surface 3.87 → 4.02 ms (within noise). Decoration is unchanged. Per change (1 thread, min): aquifer skip +5.1%; carver worker +0.6% end-to-end with carvers −9% (13 threads: carvers −21%); surface column cache +2.6%; solid fill runs +4.4%. Reproduce: ```sh cargo build --release -p horizon-world --example chunkgen_bench target/release/examples/chunkgen_bench .local/horizon-client/26.3 \ --seed 0 --size 32 --center 16 16 --threads 1 --warmup --json --no-map ``` The A/B script used here (interleaved min/median plus snapshot hashes) lives in the worktree at `target/bench/ab.py`; it is a local harness and is not part of the PR. ## Parity - `python3 tools/test_terrain_parity.py`: **7,950,873 output lines per side match** (client and server). - `python3 tools/test_material_stage_parity.py`: **6,733,382 output lines per side match**. - Snapshot hashes of 256 chunks (terrain and decorated) are identical. ## Local checks - `cargo fmt --check` passed. - `cargo clippy -p horizon-world --all-targets -- -D warnings` passed. - `cargo test -p horizon-world --lib`: 177 passed, 1 ignored. - `python3 tools/test_terrain_parity.py`: **7,950,873 output lines per side match**. - `python3 tools/test_material_stage_parity.py`: **6,733,382 output lines per side match**. 🤖 Generated with [OpenCode](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:07: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#4686
No description provided.