[PR #817] [MERGED] Ore veins: sample shared richness once, read vein densities without division #2830

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/817
Author: @ludovic111
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ludovic111

Base: main ← Head: perf/surface-rules


📝 Commits (1)

  • 6f7096b Ore veins: sample shared richness once, index the volume without division

📊 Changes

1 file changed (+142 additions, -11 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/material_condition/density.rs (+142 -11)

📄 Description

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

What

Two changes to the material stage's ore-vein densities (worldgen/material_condition/density.rs only):

  1. Richness is sampled once. In 26.3 the copper and iron vein rules both bind minecraft:overworld/ore_vein/richness eagerly, so every chunk sampled the same compiled root over the same volume twice. Eager bindings of the same root (Arc::ptr_eq) now share one buffer. Sampling a root over a fixed volume and context is deterministic, so the values are bit-identical.
  2. Lookups without division. Each solid block reads one or two vein densities through DensityVolume::index_of_block, which does a % and a / by the step on every axis. The stage's volumes are unit-step, so block_index indexes them directly and falls back to index_of_block for strided volumes. A unit test checks it against index_of_block at edges, outside the volume and at i32 wrap-around.

Why

perf-server-7, Task 1. Surface rules are about 39% of chunk generation. Profile of build_surface on main (seed 12345, 48×48 chunks, sample on the bench thread):

part of build_surface share
eager ore-vein densities (CompiledRule::compile → bind_density, almost all density arithmetic) ~47%
rule walk (CompiledRule::apply, Compiled::test, vein density reads) ~37%
column block reads (TerrainBlocks::block, BlockSection::get) ~9%
writes and heightmap updates ~8%
biome lookups (quart_at_block), surface noises ~3%

The density arithmetic is rdbt's area (#768, #796), and the constant rule branches are #801. This PR touches neither: it removes a duplicated volume and the division in the reads.

Numbers

Mac mini M4 Pro, release build, chunkgen_bench <res> --seed 12345 --size 16 --threads 1 --no-decorate. The machine is shared and busy, so the stage timers were switched locally to thread CPU time (CLOCK_THREAD_CPUTIME_ID, same patch on both builds, not in this PR). 4 alternating rounds, base/new/base/new; medians.

build surface ms/chunk (CPU) worker CPU ms/proto chunk
main b651ca5f 3.11 14.2
this PR 2.86 (−8%) 13.6
#801 2.93 (−6%) 13.6
#801 + this PR 2.68 (−14%) 13.5

CPU samples (48×48 chunks): build_surface is 32.3% → 30.8% of proto-chunk generation, and density UnaryOp::apply under it drops from 1590 to 1229 samples (the second richness pass is gone). Nether and End have no vein rules and don't change.

Byte-identical

A local FNV hash over every proto-chunk block state and biome (not in this PR) is identical to main:

  • overworld seed 12345 at (0,0): a6a74a1b6af6cfda
  • overworld seed −1 at (32,−32): a9f24bf5c6654c86
  • Nether 2e9d2a370ed76ff8, End 07374734ae465ef5

Same with #801 on top.

How tested

cargo fmt --all --check                                        ok
cargo clippy --workspace --all-targets -- -D warnings          ok
cargo test -p horizon-world                                    ok (incl. 2 new tests in material_condition::density)
PARITY_LOCAL_JOBS=4 python3 tools/parity.py material_stage material_condition material_rule_library \
  material_surface material_extension terrain chunk_generation chunk_stage server_world_gen worldgen \
  decoration decorated_region scattered_ore carving_mask cave_carver canyon_carver noise retrogen_chunk biome_chunk
                                                               19/19 PASS
python3 tools/parity.py --changed origin/main                  293 selected (everything links horizon-world);
                                                               the first 32 (a-b...) PASS, then stopped: the full
                                                               run is ~6 h on the shared Mac mini. The worldgen ones
                                                               above are the ones that reach this code; CI parity runs the rest.

Needs Ludovic

Nothing.

🤖 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/817 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/surface-rules` --- ### 📝 Commits (1) - [`6f7096b`](https://github.com/horizon-rust/horizon/commit/6f7096b39644e070d79e670389f9b22e3ef9272b) Ore veins: sample shared richness once, index the volume without division ### 📊 Changes **1 file changed** (+142 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/material_condition/density.rs` (+142 -11) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Two changes to the material stage's ore-vein densities (`worldgen/material_condition/density.rs` only): 1. **Richness is sampled once.** In 26.3 the copper and iron vein rules both bind `minecraft:overworld/ore_vein/richness` eagerly, so every chunk sampled the same compiled root over the same volume twice. Eager bindings of the same root (`Arc::ptr_eq`) now share one buffer. Sampling a root over a fixed volume and context is deterministic, so the values are bit-identical. 2. **Lookups without division.** Each solid block reads one or two vein densities through `DensityVolume::index_of_block`, which does a `%` and a `/` by the step on every axis. The stage's volumes are unit-step, so `block_index` indexes them directly and falls back to `index_of_block` for strided volumes. A unit test checks it against `index_of_block` at edges, outside the volume and at i32 wrap-around. ## Why perf-server-7, Task 1. Surface rules are about 39% of chunk generation. Profile of `build_surface` on main (seed 12345, 48×48 chunks, `sample` on the bench thread): | part of `build_surface` | share | | --- | --- | | eager ore-vein densities (`CompiledRule::compile` → `bind_density`, almost all density arithmetic) | ~47% | | rule walk (`CompiledRule::apply`, `Compiled::test`, vein density reads) | ~37% | | column block reads (`TerrainBlocks::block`, `BlockSection::get`) | ~9% | | writes and heightmap updates | ~8% | | biome lookups (`quart_at_block`), surface noises | ~3% | The density arithmetic is rdbt's area (#768, #796), and the constant rule branches are #801. This PR touches neither: it removes a duplicated volume and the division in the reads. ## Numbers Mac mini M4 Pro, release build, `chunkgen_bench <res> --seed 12345 --size 16 --threads 1 --no-decorate`. The machine is shared and busy, so the stage timers were switched locally to thread CPU time (`CLOCK_THREAD_CPUTIME_ID`, same patch on both builds, not in this PR). 4 alternating rounds, base/new/base/new; medians. | build | surface ms/chunk (CPU) | worker CPU ms/proto chunk | | --- | --- | --- | | main b651ca5f | 3.11 | 14.2 | | this PR | 2.86 (**−8%**) | 13.6 | | #801 | 2.93 (−6%) | 13.6 | | #801 + this PR | 2.68 (**−14%**) | 13.5 | CPU samples (48×48 chunks): `build_surface` is 32.3% → 30.8% of proto-chunk generation, and density `UnaryOp::apply` under it drops from 1590 to 1229 samples (the second richness pass is gone). Nether and End have no vein rules and don't change. ## Byte-identical A local FNV hash over every proto-chunk block state and biome (not in this PR) is identical to main: - overworld seed 12345 at (0,0): `a6a74a1b6af6cfda` - overworld seed −1 at (32,−32): `a9f24bf5c6654c86` - Nether `2e9d2a370ed76ff8`, End `07374734ae465ef5` Same with #801 on top. ## How tested ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-world ok (incl. 2 new tests in material_condition::density) PARITY_LOCAL_JOBS=4 python3 tools/parity.py material_stage material_condition material_rule_library \ material_surface material_extension terrain chunk_generation chunk_stage server_world_gen worldgen \ decoration decorated_region scattered_ore carving_mask cave_carver canyon_carver noise retrogen_chunk biome_chunk 19/19 PASS python3 tools/parity.py --changed origin/main 293 selected (everything links horizon-world); the first 32 (a-b...) PASS, then stopped: the full run is ~6 h on the shared Mac mini. The worldgen ones above are the ones that reach this code; CI parity runs the rest. ``` ## Needs Ludovic Nothing. 🤖 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-02 15:59:23 +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#2830
No description provided.