[PR #514] [MERGED] Stronghold ring searches run on every worker that needs them #2614

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

📋 Pull Request Information

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

Base: main ← Head: perf/stronghold-rings-on-all-workers


📝 Commits (3)

  • b9d6d1c Stronghold ring searches run on every worker that needs them
  • be6a9d2 Stronghold ring test: wrap the seed + 1 for i64::MAX
  • 24bb3f9 Stronghold ring test: rustfmt

📊 Changes

3 files changed (+214 additions, -51 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/generator_structures.rs (+142 -14)
📝 crates/horizon-world/src/worldgen/structure/start.rs (+27 -21)
📝 crates/horizon-world/src/worldgen/structure/stronghold.rs (+45 -16)

📄 Description

What

The stronghold ring positions (128 per world, each a biome search over a 57x57 quart area) are now computed by every worker that needs them, instead of by the first worker alone while all the others wait.

Why

Profiling the chunk pipeline on its worker pool (sample of a headless fill, 13 workers on the M4 Pro) showed 12 of 13 workers blocked in OnceLock::get_or_init inside StructureState::starts_at, while one worker ran stronghold::ring_positions alone. Every proto chunk asks for structure starts, so after each world load (and each return to the Overworld, which builds a new generator) nothing generated until that one worker finished: about 2 s on an M4 Pro, longer on slower cores.

Vanilla's ChunkGeneratorStructureState.generateRingPositions runs each position's findBiomeHorizontal as its own CompletableFuture on the background executor. Horizon now does the same work split the same way:

  • stronghold::ring_searches plans the ring chunks and forks each search random serially (the cheap part, same random sequence as before);
  • RingSearch::find is the biome search for one position, using only its own random;
  • RingWork (in generator_structures.rs) hands out searches by index to every thread that needs the rings before they exist; each takes searches until none are left, then waits for the rest. The positions are assembled in order, so the result is the same whatever thread ran which search. Sets with no positions keep their empty entry, as before.

/locate and the eye of ender use the same path.

Measurements

Headless chunk pipeline (streaming_bench, a small example in a follow-up PR: Streaming on VanillaTerrain, seed 1234, until every column within the radius is generated, lit and meshed). Mac mini M4 Pro, 14 threads, with other sessions running (load 40+), alternating base/new:

Fill base (origin/main) this PR
radius 2, 13 workers (mostly the rings) 2.33 s 0.67 s
radius 8, 13 workers, 3 rounds 3.28 / 4.60 / 4.02 s 1.80 / 1.58 / 1.16 s
radius 8, 3 workers, 3 rounds 7.65 / 7.78 / 3.15 s 5.11 / 4.97 / 2.21 s

ThinkPad (i7-7500U, 2 cores / 4 threads, Intel HD 620, Mesa Vulkan, --benchmark standard --render-distance 8 --offscreen, 3 workers), base x2 vs new x3:

base this PR
start to in-world 27.0 s 27.9 s
village / forest / ocean / mountain avg FPS 236 / 134 / 210 / 241 216 / 179 / 248 / 246
village / forest / ocean / mountain 1% low 31.7 / 16.4 / 30.2 / 29.8 24.3 / 21.7 / 33.9 / 28.8
chunk load per scene (ms) 12323 / 26621 / 13681 / 24145 12684 / 26771 / 10786 / 23216

No change beyond noise there: with 2 physical cores, the one worker computing the rings plus the render thread already used both cores; the extra workers only add hyperthreads. The gain is on machines with more cores than that (the 5600X / 5600GT / 7000-series reports have 6 to 8).

The Mac in-game benchmark was too noisy to quote while other sessions ran (start-to-world varied 8 to 46 s for the same binary).

How tested

  • ring_work_shared_between_threads_matches_serial_search: four threads sharing the searches of three ring sets (one empty) give exactly the serial positions, for four seeds.
  • Before committing, a temporary test compared the new ring_positions with origin/main's implementation (copied verbatim) for six seeds and 128 positions: identical.
  • cargo fmt --all --check, cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings: clean.
  • cargo test -p horizon-world --lib: 87 passed.
  • cargo test -p horizon-client --lib (fast profile): 746 passed; crash::tests fail there because that profile has no line tables (they look for crash.rs in the backtrace), and front::tests::horizon_world_delete_* passes when run alone (shared state under parallel runs). This PR touches neither.
  • Local parity, PATH=/tmp/py313:$PATH PARITY_LOCAL_JOBS=4 python3 tools/parity.py --changed origin/main: all 287 affected harnesses pass (285 in one run; worldgen and world_spawn rerun alone after that run was interrupted: both pass, world_spawn on its fresh-oracle retry).

🤖 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/514 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/stronghold-rings-on-all-workers` --- ### 📝 Commits (3) - [`b9d6d1c`](https://github.com/horizon-rust/horizon/commit/b9d6d1c7d91b7654f63fa1d58903b666af747c6c) Stronghold ring searches run on every worker that needs them - [`be6a9d2`](https://github.com/horizon-rust/horizon/commit/be6a9d2cb57c63bf8dbcc3a08238582f6d5e31f5) Stronghold ring test: wrap the seed + 1 for i64::MAX - [`24bb3f9`](https://github.com/horizon-rust/horizon/commit/24bb3f97aa21d9107fd5b6243337847fd7b0f134) Stronghold ring test: rustfmt ### 📊 Changes **3 files changed** (+214 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/generator_structures.rs` (+142 -14) 📝 `crates/horizon-world/src/worldgen/structure/start.rs` (+27 -21) 📝 `crates/horizon-world/src/worldgen/structure/stronghold.rs` (+45 -16) </details> ### 📄 Description ## What The stronghold ring positions (128 per world, each a biome search over a 57x57 quart area) are now computed by every worker that needs them, instead of by the first worker alone while all the others wait. ## Why Profiling the chunk pipeline on its worker pool (`sample` of a headless fill, 13 workers on the M4 Pro) showed 12 of 13 workers blocked in `OnceLock::get_or_init` inside `StructureState::starts_at`, while one worker ran `stronghold::ring_positions` alone. Every proto chunk asks for structure starts, so after each world load (and each return to the Overworld, which builds a new generator) nothing generated until that one worker finished: about 2 s on an M4 Pro, longer on slower cores. Vanilla's `ChunkGeneratorStructureState.generateRingPositions` runs each position's `findBiomeHorizontal` as its own `CompletableFuture` on the background executor. Horizon now does the same work split the same way: - `stronghold::ring_searches` plans the ring chunks and forks each search random serially (the cheap part, same random sequence as before); - `RingSearch::find` is the biome search for one position, using only its own random; - `RingWork` (in `generator_structures.rs`) hands out searches by index to every thread that needs the rings before they exist; each takes searches until none are left, then waits for the rest. The positions are assembled in order, so the result is the same whatever thread ran which search. Sets with no positions keep their empty entry, as before. `/locate` and the eye of ender use the same path. ## Measurements Headless chunk pipeline (`streaming_bench`, a small example in a follow-up PR: `Streaming` on `VanillaTerrain`, seed 1234, until every column within the radius is generated, lit and meshed). Mac mini M4 Pro, 14 threads, with other sessions running (load 40+), alternating base/new: | Fill | base (origin/main) | this PR | | --- | ---: | ---: | | radius 2, 13 workers (mostly the rings) | 2.33 s | 0.67 s | | radius 8, 13 workers, 3 rounds | 3.28 / 4.60 / 4.02 s | 1.80 / 1.58 / 1.16 s | | radius 8, 3 workers, 3 rounds | 7.65 / 7.78 / 3.15 s | 5.11 / 4.97 / 2.21 s | ThinkPad (i7-7500U, 2 cores / 4 threads, Intel HD 620, Mesa Vulkan, `--benchmark standard --render-distance 8 --offscreen`, 3 workers), base x2 vs new x3: | | base | this PR | | --- | ---: | ---: | | start to in-world | 27.0 s | 27.9 s | | village / forest / ocean / mountain avg FPS | 236 / 134 / 210 / 241 | 216 / 179 / 248 / 246 | | village / forest / ocean / mountain 1% low | 31.7 / 16.4 / 30.2 / 29.8 | 24.3 / 21.7 / 33.9 / 28.8 | | chunk load per scene (ms) | 12323 / 26621 / 13681 / 24145 | 12684 / 26771 / 10786 / 23216 | No change beyond noise there: with 2 physical cores, the one worker computing the rings plus the render thread already used both cores; the extra workers only add hyperthreads. The gain is on machines with more cores than that (the 5600X / 5600GT / 7000-series reports have 6 to 8). The Mac in-game benchmark was too noisy to quote while other sessions ran (start-to-world varied 8 to 46 s for the same binary). ## How tested - `ring_work_shared_between_threads_matches_serial_search`: four threads sharing the searches of three ring sets (one empty) give exactly the serial positions, for four seeds. - Before committing, a temporary test compared the new `ring_positions` with origin/main's implementation (copied verbatim) for six seeds and 128 positions: identical. - `cargo fmt --all --check`, `cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings`: clean. - `cargo test -p horizon-world --lib`: 87 passed. - `cargo test -p horizon-client --lib` (`fast` profile): 746 passed; `crash::tests` fail there because that profile has no line tables (they look for `crash.rs` in the backtrace), and `front::tests::horizon_world_delete_*` passes when run alone (shared state under parallel runs). This PR touches neither. - Local parity, `PATH=/tmp/py313:$PATH PARITY_LOCAL_JOBS=4 python3 tools/parity.py --changed origin/main`: all 287 affected harnesses pass (285 in one run; `worldgen` and `world_spawn` rerun alone after that run was interrupted: both pass, `world_spawn` on its fresh-oracle retry). 🤖 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:57:38 +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#2614
No description provided.