[PR #1760] [MERGED] World generation: workers build free structure starts instead of queueing #3747

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

📋 Pull Request Information

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

Base: main ← Head: perf/structure-start-convoy


📝 Commits (5)

  • 4eb85db World generation: workers build free structure starts instead of queueing
  • e2ca936 Merge main
  • 67591ed Merge remote-tracking branch 'origin/main' into perf/structure-start-convoy
  • a62fa73 Merge remote-tracking branch 'origin/main' into HEAD
  • fd16400 Merge remote-tracking branch 'origin/main' into HEAD

📊 Changes

2 files changed (+56 additions, -25 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/generator.rs (+18 -5)
📝 crates/horizon-world/src/worldgen/generator_structures.rs (+38 -20)

📄 Description

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

World generation at a cold start (a new world, a seed's first structures): the workers no longer queue behind each other's structure starts.

ChunkGenerator.createReferences asks for the structure starts of the 17x17 chunks around each chunk. Each Horizon worker asked for them in the same order, and when another worker was building one of them it waited on that chunk's work lock. The result was a convoy: one worker built and the others waited behind it.

  • references() now makes two passes. The first builds the starts that nobody else is building (try_lock). The second waits only for the ones another worker was building.
  • ChunkWork, the map of per-chunk work locks, is sharded (64 shards, same hash as StartCache). Each worker now takes the locks for the whole 17x17 neighbourhood, and a single mutex there became the next contention point.

Same starts, same reference order. Each chunk's starts are still built once and kept by the first builder. Vanilla has no equivalent lock: this is Horizon's own worker pool.

Measured

Sampled blocked time (__psynch_mutexwait) as a share of generation samples. Mac mini M4 Pro, fresh generator, 12 workers, chunk_load_bench (#1747):

blocked of generation samples
main 19,110 / 48,980 39%
two passes only 9,857 / 36,815 27%
two passes + sharded locks (this PR) 156 / 11,424 1.4%

The Mac was under load average 60-100 from other sessions during this run, so wall-clock A/B there was noise. Blocked time is the figure that held still across runs.

  • In-game world entry at RD 16 on main showed 14% of generation samples in this lock.
  • After a teleport, with structure data already built, it is 1.6%. Loading in an explored world doesn't change.
  • ThinkPad (i5-7200U, 3 workers), the same bench: 5,814 ms on main vs 5,742 ms with this PR. With 3 workers there is no convoy to remove, so the change is neutral there.

Self-check

pr_ready (tools/pr_ready.py on ludovics-mac-mini, against origin/main at 4a675206b, 20 min 22 s)

Check Result
Scope ✅ 2 files, +56 −25
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (36 s)
tests: horizon-world ✅ 236 passed (1 min 40 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 312 affected, 46 passed (17 min 24 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Parity: all 312 harnesses this change can affect pass at this head. 266 ran in a first pass that hit its time limit; their results are cached by input hash, and the rerun ran the remaining 46.

No label: a speed-up with no visible change.

🤖 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/1760 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `perf/structure-start-convoy` --- ### 📝 Commits (5) - [`4eb85db`](https://github.com/horizon-rust/horizon/commit/4eb85dbdf96468d2d8b38ca522372bd9006aa3dd) World generation: workers build free structure starts instead of queueing - [`e2ca936`](https://github.com/horizon-rust/horizon/commit/e2ca9364878da96aa2e3f538bb3294c39fa6178e) Merge main - [`67591ed`](https://github.com/horizon-rust/horizon/commit/67591edf8f5a365add4c72d93492984550755a54) Merge remote-tracking branch 'origin/main' into perf/structure-start-convoy - [`a62fa73`](https://github.com/horizon-rust/horizon/commit/a62fa7375d0410b49adfcf7fa4ee4738f4899cef) Merge remote-tracking branch 'origin/main' into HEAD - [`fd16400`](https://github.com/horizon-rust/horizon/commit/fd16400b911a6ff62c0eab8b85b6d1d9dbed3eb3) Merge remote-tracking branch 'origin/main' into HEAD ### 📊 Changes **2 files changed** (+56 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/generator.rs` (+18 -5) 📝 `crates/horizon-world/src/worldgen/generator_structures.rs` (+38 -20) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. World generation at a cold start (a new world, a seed's first structures): the workers no longer queue behind each other's structure starts. `ChunkGenerator.createReferences` asks for the structure starts of the 17x17 chunks around each chunk. Each Horizon worker asked for them in the same order, and when another worker was building one of them it waited on that chunk's work lock. The result was a convoy: one worker built and the others waited behind it. - `references()` now makes two passes. The first builds the starts that nobody else is building (`try_lock`). The second waits only for the ones another worker was building. - `ChunkWork`, the map of per-chunk work locks, is sharded (64 shards, same hash as `StartCache`). Each worker now takes the locks for the whole 17x17 neighbourhood, and a single mutex there became the next contention point. Same starts, same reference order. Each chunk's starts are still built once and kept by the first builder. Vanilla has no equivalent lock: this is Horizon's own worker pool. ## Measured Sampled blocked time (`__psynch_mutexwait`) as a share of generation samples. Mac mini M4 Pro, fresh generator, 12 workers, `chunk_load_bench` (#1747): | | blocked | of generation samples | |---|---|---| | main | 19,110 / 48,980 | **39%** | | two passes only | 9,857 / 36,815 | 27% | | two passes + sharded locks (this PR) | 156 / 11,424 | **1.4%** | The Mac was under load average 60-100 from other sessions during this run, so wall-clock A/B there was noise. Blocked time is the figure that held still across runs. - In-game world entry at RD 16 on main showed 14% of generation samples in this lock. - After a teleport, with structure data already built, it is 1.6%. Loading in an explored world doesn't change. - ThinkPad (i5-7200U, 3 workers), the same bench: 5,814 ms on main vs 5,742 ms with this PR. With 3 workers there is no convoy to remove, so the change is neutral there. ## Self-check **pr_ready** (`tools/pr_ready.py` on ludovics-mac-mini, against origin/main at 4a675206b, 20 min 22 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +56 −25 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (36 s) | | tests: horizon-world | ✅ 236 passed (1 min 40 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 312 affected, 46 passed (17 min 24 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Parity: all 312 harnesses this change can affect pass at this head. 266 ran in a first pass that hit its time limit; their results are cached by input hash, and the rerun ran the remaining 46. No label: a speed-up with no visible change. 🤖 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:12:01 +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#3747
No description provided.