[PR #2005] [MERGED] Stronghold rings: first chunks no longer wait for them #3931

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

📋 Pull Request Information

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

Base: main ← Head: perf/rings-out-of-reach


📝 Commits (6)

  • 4a2b262 Structure starts: decide chunks no ring search can reach without the rings
  • 7092d5f Merge remote-tracking branch 'origin/main' into perf/rings-out-of-reach
  • 0a8af38 Rings: search them on a thread behind the server, as the world opens
  • 1dd4758 Ring search thread: the idle class, not behind the server
  • 8b26c4c Ring search thread: start once generation pauses
  • 96290f4 Merge remote-tracking branch 'origin/main' into perf/rings-out-of-reach

📊 Changes

7 files changed (+262 additions, -24 deletions)

View changed files

📝 crates/horizon-client/src/game/world_loading.rs (+3 -0)
📝 crates/horizon-client/src/vanillagen.rs (+56 -2)
📝 crates/horizon-threads/src/lib.rs (+54 -0)
📝 crates/horizon-world/src/worldgen/generator.rs (+50 -9)
📝 crates/horizon-world/src/worldgen/generator_structures.rs (+74 -11)
📝 crates/horizon-world/src/worldgen/structure/start.rs (+12 -0)
📝 crates/horizon-world/src/worldgen/structure/stronghold.rs (+13 -2)

📄 Description

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

A fresh world's first chunks no longer wait for the stronghold rings.

Vanilla works out the concentric ring positions (ChunkGeneratorStructureState.generateRingPositions: 128 biome searches of 57×57 quarts for minecraft:strongholds) on its background executor as the level starts. Structure starts for that set wait for the result. Horizon ran the searches when the first chunk's structure starts were decided. Workers shared them, but every chunk waited: on a 4-thread laptop both workers spent 2.5 s on them before the first chunk could finish.

Now:

  • A chunk no ring search can reach is decided without the rings. Each search ends on its ring chunk or inside the square it samples (RingSearch::may_land_near, 28 quarts plus a chunk's rounding). Exclusion zones and avoid ranges add their reach (StructureRegistry::zone_reach). A chunk farther than that from every search's ring chunk gets an empty Rings, which is what the rings would say there. Strongholds lie 1,400 blocks out or more, so spawn chunks never wait. A chunk near a ring, or /locate, computes them as before (shared between the threads that ask).
  • The searches still run early, on a thread of their own. As vanilla's executor does, without taking cores from the first chunks: the thread starts in the idle class (horizon_threads::idle_current: SCHED_IDLE on Linux, background QoS on macOS, idle priority on Windows) and waits until no proto chunk was made for 2 s, or a minute at most. If the world closes first, it does nothing. Eyes of ender and /locate then find the rings ready.

The positions are vanilla's: the same searches, the same order and the same random draws. Only when they run moved. Tests:

  • ring_searches_end_where_they_may: the bound holds for every search, seed and corner.
  • chunks_far_from_the_rings_do_not_search_them: chunks across ±24 chunks of spawn leave the rings unsearched and get the same starts before and after the rings are forced.
  • stronghold_rings_match_vanilla: still passes.

Measured

ThinkPad (i5-7200U, 4 threads), fresh world with --offscreen --creative at default settings, alternated, 1-minute load 1.4–4:

main this branch
first chunk 8.3 / 8.9 / 9.0 s 6.3 / 5.8 / 5.9 s
600 chunks 26.7 / 30.5 / 33.5 s 25.7 / 27.5 / 28.5 s
/locate structure minecraft:stronghold once loaded 0.1 s 0.06 s (after the pause; 3.2 s without the background thread)

First chunk −2.9 s (−33%). Two earlier versions of the background thread were measured on the same machine and changed: at nice +10, then in the idle class from the start. Either way the thread slowed the first 600 chunks by about 3 s (a hyperthread shares a physical core with a worker), so it now waits for the pause.

Paths: world generation is shared by the server thread, the in-frame path and the dedicated server. make_streaming starts the thread for the overworld whenever structures are on. world_spawn, worldgen, chunk_generation and the structure harnesses run in the self-check below.

Self-check

pr_ready (tools/pr_ready.py on Ludovics-Mac-mini, against origin/main at b3149d43e, 99 min 28 s)

Check Result
Scope ✅ 11 files, +361 −48
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 299 run, FAILED (errors=2) (1 min 52 s)
rustfmt ✅ (13 s)
clippy ✅ (1 min 18 s)
tests: horizon-client, horizon-threads, horizon-world ✅ 1500 passed (11 min 47 s)
doc tests ✅ 0 passed (9 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 91 affected, 91 passed (82 min 34 s)

One run for three branches: a merge of perf/sculk-ticking-chunks, perf/rings-out-of-reach (at 8b26c4cf3), perf/behaviour-cache-hash-once and #1991 (pr_ready's selection fix, without which pr_ready did not get past its plan). The 2 Python errors are main's on macOS (OracleReuseTests exit 127, a /private/var path in ParityRunnerTests); none of these branches touch Python.

🤖 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/2005 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/rings-out-of-reach` --- ### 📝 Commits (6) - [`4a2b262`](https://github.com/horizon-rust/horizon/commit/4a2b262343581332c58998410c8884c9d82c6558) Structure starts: decide chunks no ring search can reach without the rings - [`7092d5f`](https://github.com/horizon-rust/horizon/commit/7092d5f4d7d2e1d60290d1fa190b0f399105dcc9) Merge remote-tracking branch 'origin/main' into perf/rings-out-of-reach - [`0a8af38`](https://github.com/horizon-rust/horizon/commit/0a8af38ac4ed1094a871eacae8338c4b95c636d5) Rings: search them on a thread behind the server, as the world opens - [`1dd4758`](https://github.com/horizon-rust/horizon/commit/1dd47581de0fece92a193888e0a9518632edc787) Ring search thread: the idle class, not behind the server - [`8b26c4c`](https://github.com/horizon-rust/horizon/commit/8b26c4cf348e48ccf9d47acdb08984665ed45a84) Ring search thread: start once generation pauses - [`96290f4`](https://github.com/horizon-rust/horizon/commit/96290f4b94a4f204643c24f8f9d3a7d5d87a4868) Merge remote-tracking branch 'origin/main' into perf/rings-out-of-reach ### 📊 Changes **7 files changed** (+262 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/world_loading.rs` (+3 -0) 📝 `crates/horizon-client/src/vanillagen.rs` (+56 -2) 📝 `crates/horizon-threads/src/lib.rs` (+54 -0) 📝 `crates/horizon-world/src/worldgen/generator.rs` (+50 -9) 📝 `crates/horizon-world/src/worldgen/generator_structures.rs` (+74 -11) 📝 `crates/horizon-world/src/worldgen/structure/start.rs` (+12 -0) 📝 `crates/horizon-world/src/worldgen/structure/stronghold.rs` (+13 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. A fresh world's first chunks no longer wait for the stronghold rings. Vanilla works out the concentric ring positions (`ChunkGeneratorStructureState.generateRingPositions`: 128 biome searches of 57×57 quarts for `minecraft:strongholds`) on its background executor as the level starts. Structure starts for that set wait for the result. Horizon ran the searches when the first chunk's structure starts were decided. Workers shared them, but every chunk waited: on a 4-thread laptop both workers spent 2.5 s on them before the first chunk could finish. Now: - **A chunk no ring search can reach is decided without the rings.** Each search ends on its ring chunk or inside the square it samples (`RingSearch::may_land_near`, 28 quarts plus a chunk's rounding). Exclusion zones and `avoid` ranges add their reach (`StructureRegistry::zone_reach`). A chunk farther than that from every search's ring chunk gets an empty `Rings`, which is what the rings would say there. Strongholds lie 1,400 blocks out or more, so spawn chunks never wait. A chunk near a ring, or `/locate`, computes them as before (shared between the threads that ask). - **The searches still run early, on a thread of their own.** As vanilla's executor does, without taking cores from the first chunks: the thread starts in the idle class (`horizon_threads::idle_current`: `SCHED_IDLE` on Linux, background QoS on macOS, idle priority on Windows) and waits until no proto chunk was made for 2 s, or a minute at most. If the world closes first, it does nothing. Eyes of ender and `/locate` then find the rings ready. The positions are vanilla's: the same searches, the same order and the same random draws. Only when they run moved. Tests: - `ring_searches_end_where_they_may`: the bound holds for every search, seed and corner. - `chunks_far_from_the_rings_do_not_search_them`: chunks across ±24 chunks of spawn leave the rings unsearched and get the same starts before and after the rings are forced. - `stronghold_rings_match_vanilla`: still passes. ## Measured ThinkPad (i5-7200U, 4 threads), fresh world with `--offscreen --creative` at default settings, alternated, 1-minute load 1.4–4: | | main | this branch | |---|---|---| | first chunk | 8.3 / 8.9 / 9.0 s | 6.3 / 5.8 / 5.9 s | | 600 chunks | 26.7 / 30.5 / 33.5 s | 25.7 / 27.5 / 28.5 s | | `/locate structure minecraft:stronghold` once loaded | 0.1 s | 0.06 s (after the pause; 3.2 s without the background thread) | First chunk −2.9 s (−33%). Two earlier versions of the background thread were measured on the same machine and changed: at nice +10, then in the idle class from the start. Either way the thread slowed the first 600 chunks by about 3 s (a hyperthread shares a physical core with a worker), so it now waits for the pause. Paths: world generation is shared by the server thread, the in-frame path and the dedicated server. `make_streaming` starts the thread for the overworld whenever structures are on. `world_spawn`, `worldgen`, `chunk_generation` and the structure harnesses run in the self-check below. ## Self-check **pr_ready** (`tools/pr_ready.py` on Ludovics-Mac-mini, against origin/main at b3149d43e, 99 min 28 s) | Check | Result | | --- | --- | | Scope | ✅ 11 files, +361 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 299 run, FAILED (errors=2) (1 min 52 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (1 min 18 s) | | tests: horizon-client, horizon-threads, horizon-world | ✅ 1500 passed (11 min 47 s) | | doc tests | ✅ 0 passed (9 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 91 affected, 91 passed (82 min 34 s) | One run for three branches: a merge of `perf/sculk-ticking-chunks`, `perf/rings-out-of-reach` (at 8b26c4cf3), `perf/behaviour-cache-hash-once` and #1991 (pr_ready's selection fix, without which pr_ready did not get past its plan). The 2 Python errors are main's on macOS (`OracleReuseTests` exit 127, a `/private/var` path in `ParityRunnerTests`); none of these branches touch Python. 🤖 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-03 04:13:21 +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#3931
No description provided.