[PR #752] [MERGED] Biome zoom: mix the shared corner prefixes once in quart_at_block #2779

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

📋 Pull Request Information

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

Base: main ← Head: perf/biome-zoom-shared-mix


📝 Commits (1)

  • f021547 Biome zoom: mix the shared corner prefixes once in quart_at_block

📊 Changes

1 file changed (+178 additions, -25 deletions)

View changed files

📝 crates/horizon-core/src/biome.rs (+178 -25)

📄 Description

Opened by rdbt's AI agent (opencode), not by rdbt himself.

What and why

BiomeManager.getBiome asks getFiddledDistance for all eight quart corners, and each call restarts the same six-step LinearCongruentialGenerator mix from the world seed. The first two steps depend only on the corner's X and Y offsets; the third only adds Z. So all eight corners recompute the same shared prefix states.

BiomeZoom::quart_at_block now mixes the two X states, then the four XY states, once, and finishes the remaining steps (the Z step, the repeated X/Y/Z tail, and the two seed steps) for the eight corners. Because next(m, salt + offset) == next(m, salt) + offset, each coordinate folds into its step with a single addition. Corner order, the strict > tie comparison and signed wrapping are unchanged.

The lookup is hot on two of the three paths in the profiling thread: biome-chunk lookups, and the material-rules surface pass, which calls BiomeZoom::quart_at_block once per (column, y) through Context::biome.

Vanilla reference

Checked with tools/rea_vanilla.py; this is a pure speed change, not a behaviour change.

  • net.minecraft.world.level.biome.BiomeManager.getBiome(int, int, int) - corner order i = 0..8, cornerX/Y/Z = parent + ((i >> 2|1|0) & 1), distanceX/Y/Z = fract - offset, strict minFiddledDistance > next.
  • net.minecraft.world.level.biome.BiomeManager.getFiddledDistance(long, int, int, int, double, double, double) - six LinearCongruentialGenerator.next over x, y, z, x, y, z, then two next(rval, seed); Mth.square of each fiddled axis.
  • net.minecraft.util.LinearCongruentialGenerator.next(long, long) and BiomeManager.getFiddle(long).

Harness: tools/test_biome_zoom_parity.py (also covers obfuscate_seed and noise_quart_at_block). A new unit test, biome::tests::quart_at_block_matches_reference, pins the result against the per-corner oracle over a dense grid (67^3 positions per seed, 7 seeds) plus wrapping extremes near i32::MIN/MAX; it is bit-exact.

Numbers

Isolated quart_at_block (best of 5, 64^3 positions x 24 rounds, seed 0x0123456789abcdef, --profile fast):

ns/call
per-corner oracle 77.7
prefix-shared 45.4
speedup 41.6%

chunkgen_bench, 64 chunks, 1 thread, --no-decorate, alternating base/new runs on a busy host (load ~80; best of 4):

stage before after
biomes 0.86 ms 0.87 ms
noise 7.14 ms 7.16 ms
surface (material rules) 8.92 ms 7.96 ms
carvers 2.08 ms 2.05 ms

The surface pass, which is the material-rules path, drops ~10-11%; biomes and noise are unchanged (the aquifer does not call the zoom).

Self-check

**pr_ready** (`tools/pr_ready.py --base origin/main` on archlinux, against origin/main at 9b97ba09d, 46 s)

| Check | Result |
| --- | --- |
| Scope | OK 1 files, +178 −25 |
| Cargo.lock | OK unchanged |
| Public tree | OK |
| Python tests | - no Python change |
| rustfmt | OK (6 s) |
| clippy | OK (30 s) |
| tests: horizon-core | OK 93 passed (9 s) |
| tokens.css up to date | - theme untouched |
| launcher rustfmt | - launcher untouched |
| launcher clippy | - launcher untouched |
| launcher tests | - launcher untouched |
| Parity | - not run (no vanilla data here): CI's parity job picks the affected harnesses |

cargo test -p horizon-world --test biome_region --test material_stage --test biome_data also passes locally.

Screenshots

None: no player-visible change.

Please tick "Allow edits by maintainers" so fixups can be pushed without a round trip.


🔄 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/752 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/biome-zoom-shared-mix` --- ### 📝 Commits (1) - [`f021547`](https://github.com/horizon-rust/horizon/commit/f0215473e3bed0abc33dd3f89f310978621d8479) Biome zoom: mix the shared corner prefixes once in quart_at_block ### 📊 Changes **1 file changed** (+178 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/biome.rs` (+178 -25) </details> ### 📄 Description Opened by rdbt's AI agent (opencode), not by rdbt himself. ## What and why `BiomeManager.getBiome` asks `getFiddledDistance` for all eight quart corners, and each call restarts the same six-step `LinearCongruentialGenerator` mix from the world seed. The first two steps depend only on the corner's X and Y offsets; the third only adds Z. So all eight corners recompute the same shared prefix states. `BiomeZoom::quart_at_block` now mixes the two X states, then the four XY states, once, and finishes the remaining steps (the Z step, the repeated X/Y/Z tail, and the two `seed` steps) for the eight corners. Because `next(m, salt + offset) == next(m, salt) + offset`, each coordinate folds into its step with a single addition. Corner order, the strict `>` tie comparison and signed wrapping are unchanged. The lookup is hot on two of the three paths in the profiling thread: biome-chunk lookups, and the material-rules surface pass, which calls `BiomeZoom::quart_at_block` once per (column, y) through `Context::biome`. ## Vanilla reference Checked with `tools/rea_vanilla.py`; this is a pure speed change, not a behaviour change. - `net.minecraft.world.level.biome.BiomeManager.getBiome(int, int, int)` - corner order `i = 0..8`, `cornerX/Y/Z = parent + ((i >> 2|1|0) & 1)`, `distanceX/Y/Z = fract - offset`, strict `minFiddledDistance > next`. - `net.minecraft.world.level.biome.BiomeManager.getFiddledDistance(long, int, int, int, double, double, double)` - six `LinearCongruentialGenerator.next` over `x, y, z, x, y, z`, then two `next(rval, seed)`; `Mth.square` of each fiddled axis. - `net.minecraft.util.LinearCongruentialGenerator.next(long, long)` and `BiomeManager.getFiddle(long)`. Harness: `tools/test_biome_zoom_parity.py` (also covers `obfuscate_seed` and `noise_quart_at_block`). A new unit test, `biome::tests::quart_at_block_matches_reference`, pins the result against the per-corner oracle over a dense grid (67^3 positions per seed, 7 seeds) plus wrapping extremes near `i32::MIN`/`MAX`; it is bit-exact. ## Numbers Isolated `quart_at_block` (best of 5, 64^3 positions x 24 rounds, seed `0x0123456789abcdef`, `--profile fast`): | | ns/call | |---|---:| | per-corner oracle | 77.7 | | prefix-shared | 45.4 | | **speedup** | **41.6%** | `chunkgen_bench`, 64 chunks, 1 thread, `--no-decorate`, alternating base/new runs on a busy host (load ~80; best of 4): | stage | before | after | |---|---:|---:| | biomes | 0.86 ms | 0.87 ms | | noise | 7.14 ms | 7.16 ms | | **surface (material rules)** | **8.92 ms** | **7.96 ms** | | carvers | 2.08 ms | 2.05 ms | The surface pass, which is the material-rules path, drops ~10-11%; `biomes` and `noise` are unchanged (the aquifer does not call the zoom). ## Self-check ``` **pr_ready** (`tools/pr_ready.py --base origin/main` on archlinux, against origin/main at 9b97ba09d, 46 s) | Check | Result | | --- | --- | | Scope | OK 1 files, +178 −25 | | Cargo.lock | OK unchanged | | Public tree | OK | | Python tests | - no Python change | | rustfmt | OK (6 s) | | clippy | OK (30 s) | | tests: horizon-core | OK 93 passed (9 s) | | tokens.css up to date | - theme untouched | | launcher rustfmt | - launcher untouched | | launcher clippy | - launcher untouched | | launcher tests | - launcher untouched | | Parity | - not run (no vanilla data here): CI's parity job picks the affected harnesses | ``` `cargo test -p horizon-world --test biome_region --test material_stage --test biome_data` also passes locally. ## Screenshots None: no player-visible change. Please tick "Allow edits by maintainers" so fixups can be pushed without a round trip. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:58:59 +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#2779
No description provided.