[PR #1606] [MERGED] Batch cached Perlin Y samples for portable SIMD #3624

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

📋 Pull Request Information

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

Base: main ← Head: t3/vectorize-perlin-noise


📝 Commits (2)

  • 66070b9 Batch cached Perlin Y samples for portable SIMD
  • 8800d18 Perlin volume: one loop with a BATCH switch instead of a test copy

📊 Changes

1 file changed (+122 additions, -4 deletions)

View changed files

📝 crates/horizon-core/src/noise/perlin.rs (+122 -4)

📄 Description

🤖 Opened by rdbtCVS’s AI agent (Codex, gpt-6.1-sol), not by rdbtCVS himself.

What and why

Perlin volume accumulation already caches Y setup, X permutations and each Y cell's gradients. Batch four consecutive samples sharing a Y cell so LLVM can vectorize their interpolation together. The default portable x86_64 release emits four-wide SSE arithmetic and output stores. This uses safe Rust arrays without dependencies, target-feature flags, unsafe code or runtime ISA dispatch; ordinary scalar lowering remains available to other targets. Cell boundaries and tails retain scalar evaluation.

Every lane preserves the original f32 operation order, coordinate wrapping, smeared-Y handling, layer accumulation and buffer suffix. There is no FMA, fast-math or reassociation. Bitwise differential tests retain the original scalar loop as a reference and exercise vector groups, tails, stack/heap heights, extreme/negative/wrapped coordinates and exceptional inputs.

On Ryzen 5 5600X, rustc 1.99.0/LLVM 23.1.1, two independent batches of nine fresh-process AB/BA pairs use release/thin-LTO/codegen-units=1, the default target CPU, size16, warmup and decoration ON. Primary metric is proto generation plus decoration wall time, excluding resource loading and lighting. Median paired wall-time reductions and 95% paired bootstrap CIs:

  • Nether, seed1234, center0,0, one thread: 4.70% [3.70, 6.17] and 4.62% [1.87, 6.21]. Both exceed twice observed relative MAD. Proto CPU medians fall 1.09→1.04s and 1.08→1.03s.
  • Overworld, seed0, center0,0, one thread: 2.03% [1.01, 2.72] and 1.88% [1.45, 3.16].
  • Overworld, seed−1, center−32,48, one thread: 1.22% [−0.05, 2.78] and 2.71% [1.50, 4.11].
  • End, seed1234, center64,64, one thread: 1.19% [−2.28, 4.25] and 0.14% [−4.35, 1.71]. Additional size48 batches on both binaries: −0.02% [−0.92, 1.56] and −1.82% [−2.64, 1.85].
  • Four-thread origin Overworld: 2.57% [−1.08, 4.12] and −0.42% [−2.21, 2.17].

Positive means less elapsed time, computed as 100×(1−candidate/baseline). This supports a scoped Nether benefit; End and four-thread gains are unresolved. No workload has a repeatable >2% median regression. Peak RSS is effectively unchanged; the benchmark binary grows 768 bytes. The ignored diagnostic microkernel shows low-frequency gains but 6–9% overhead for frequent cell changes; it is not the acceptance metric. Other CPU architectures were not benchmarked.

Build/run example (compare against base 29c5e65d17d216c3cc84cd092a9298ee20994c73 with the same settings):

cargo build --release --locked -p horizon-world --example chunkgen_bench
# Use a private target/output directory and your own prepared resources.
chunkgen_bench "$RESOURCES" --seed 1234 --size 16 --threads 1 \
  --center 0 0 --dimension the_nether --warmup --json --no-map

Vanilla reference

Pinned Java Edition 26.3 bytecode: PerlinNoise.addToVolume, SmearedPerlinNoise.addToVolume / computeFudgeY, and Mth.lerp3 / lerp2 / lerp. Retains the existing cached X/Z dot products, cell refresh behavior, corner multiplication/addition and x→y→z interpolation order.

Self-check

  • Release horizon-core library tests: 104 passed, 3 ignored. New differential compares 2,880 volume pairs via to_bits, without tolerance.
  • All 28 cold/warm terrain and decorated snapshot comparisons are byte-identical across the fixed matrix plus far and boundary coordinates. Covers sections/blocks, biomes, heightmaps, structures, postprocessing, scheduled ticks, block entities and entities; no normalization.
  • Full python3 tools/pr_ready.py --base 29c5e65d17d216c3cc84cd092a9298ee20994c73 was intentionally stopped at the user's request after 204 passing harnesses, no recorded failures (exit143). The remaining broad harnesses were waived for this PR. This is not a full pr_ready pass.
  • Completed named checks include noise (1,443,539 lines per client/server), density (15,524,627 server lines), chunk_generation (2,372 chunks, 27 biomes, 225 structure sites, zero differences), material_stage, decoration/decorated_region, biome generation and dedicated_server. Named terrain/worldgen harnesses were not completed before cancellation.
  • cargo fmt --all -- --check, git diff --check, public-tree check, and cargo clippy --locked -p horizon-core --lib --tests -- -D warnings passed. Broad dependent-crate lint/tests were not completed by the interrupted full gate.

All measurements and checks use private output/data homes; no Mojang or prepared files are included. Builds and benchmarks were serial. During the correctness gate only, three oracle/probe workers shared one compilation lock for Cargo/javac.

🤖 Generated with Codex (gpt-6.1-sol).


🔄 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/1606 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `t3/vectorize-perlin-noise` --- ### 📝 Commits (2) - [`66070b9`](https://github.com/horizon-rust/horizon/commit/66070b918eae4dd46119c67499f7915491603c40) Batch cached Perlin Y samples for portable SIMD - [`8800d18`](https://github.com/horizon-rust/horizon/commit/8800d1878a9c903942da4f65e65386c562aa73af) Perlin volume: one loop with a BATCH switch instead of a test copy ### 📊 Changes **1 file changed** (+122 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/noise/perlin.rs` (+122 -4) </details> ### 📄 Description > 🤖 Opened by rdbtCVS’s AI agent (Codex, gpt-6.1-sol), not by rdbtCVS himself. ## What and why Perlin volume accumulation already caches Y setup, X permutations and each Y cell's gradients. Batch four consecutive samples sharing a Y cell so LLVM can vectorize their interpolation together. The default portable x86_64 release emits four-wide SSE arithmetic and output stores. This uses safe Rust arrays without dependencies, target-feature flags, unsafe code or runtime ISA dispatch; ordinary scalar lowering remains available to other targets. Cell boundaries and tails retain scalar evaluation. Every lane preserves the original f32 operation order, coordinate wrapping, smeared-Y handling, layer accumulation and buffer suffix. There is no FMA, fast-math or reassociation. Bitwise differential tests retain the original scalar loop as a reference and exercise vector groups, tails, stack/heap heights, extreme/negative/wrapped coordinates and exceptional inputs. On Ryzen 5 5600X, rustc 1.99.0/LLVM 23.1.1, two independent batches of nine fresh-process AB/BA pairs use release/thin-LTO/codegen-units=1, the default target CPU, size16, warmup and decoration ON. Primary metric is proto generation plus decoration wall time, excluding resource loading and lighting. Median paired wall-time reductions and 95% paired bootstrap CIs: - Nether, seed1234, center0,0, one thread: **4.70% [3.70, 6.17]** and **4.62% [1.87, 6.21]**. Both exceed twice observed relative MAD. Proto CPU medians fall 1.09→1.04s and 1.08→1.03s. - Overworld, seed0, center0,0, one thread: 2.03% [1.01, 2.72] and 1.88% [1.45, 3.16]. - Overworld, seed−1, center−32,48, one thread: 1.22% [−0.05, 2.78] and 2.71% [1.50, 4.11]. - End, seed1234, center64,64, one thread: 1.19% [−2.28, 4.25] and 0.14% [−4.35, 1.71]. Additional size48 batches on both binaries: −0.02% [−0.92, 1.56] and −1.82% [−2.64, 1.85]. - Four-thread origin Overworld: 2.57% [−1.08, 4.12] and −0.42% [−2.21, 2.17]. Positive means less elapsed time, computed as 100×(1−candidate/baseline). This supports a scoped Nether benefit; End and four-thread gains are unresolved. No workload has a repeatable >2% median regression. Peak RSS is effectively unchanged; the benchmark binary grows 768 bytes. The ignored diagnostic microkernel shows low-frequency gains but 6–9% overhead for frequent cell changes; it is not the acceptance metric. Other CPU architectures were not benchmarked. Build/run example (compare against base `29c5e65d17d216c3cc84cd092a9298ee20994c73` with the same settings): ```sh cargo build --release --locked -p horizon-world --example chunkgen_bench # Use a private target/output directory and your own prepared resources. chunkgen_bench "$RESOURCES" --seed 1234 --size 16 --threads 1 \ --center 0 0 --dimension the_nether --warmup --json --no-map ``` ## Vanilla reference Pinned Java Edition 26.3 bytecode: `PerlinNoise.addToVolume`, `SmearedPerlinNoise.addToVolume` / `computeFudgeY`, and `Mth.lerp3` / `lerp2` / `lerp`. Retains the existing cached X/Z dot products, cell refresh behavior, corner multiplication/addition and x→y→z interpolation order. ## Self-check - Release `horizon-core` library tests: 104 passed, 3 ignored. New differential compares 2,880 volume pairs via `to_bits`, without tolerance. - All 28 cold/warm terrain and decorated snapshot comparisons are byte-identical across the fixed matrix plus far and boundary coordinates. Covers sections/blocks, biomes, heightmaps, structures, postprocessing, scheduled ticks, block entities and entities; no normalization. - Full `python3 tools/pr_ready.py --base 29c5e65d17d216c3cc84cd092a9298ee20994c73` was **intentionally stopped at the user's request after 204 passing harnesses, no recorded failures (exit143)**. The remaining broad harnesses were waived for this PR. **This is not a full pr_ready pass.** - Completed named checks include noise (1,443,539 lines per client/server), density (15,524,627 server lines), chunk_generation (2,372 chunks, 27 biomes, 225 structure sites, zero differences), material_stage, decoration/decorated_region, biome generation and dedicated_server. Named terrain/worldgen harnesses were not completed before cancellation. - `cargo fmt --all -- --check`, `git diff --check`, public-tree check, and `cargo clippy --locked -p horizon-core --lib --tests -- -D warnings` passed. Broad dependent-crate lint/tests were not completed by the interrupted full gate. All measurements and checks use private output/data homes; no Mojang or prepared files are included. Builds and benchmarks were serial. During the correctness gate only, three oracle/probe workers shared one compilation lock for Cargo/javac. 🤖 Generated with [Codex](https://openai.com/codex/) (gpt-6.1-sol). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:10:52 +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#3624
No description provided.