[PR #1805] [MERGED] Add /pregen: generate, light and save an area ahead of players #3777

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

📋 Pull Request Information

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

Base: main ← Head: pr/pregen


📝 Commits (5)

  • 1506c18 Add /pregen: generate, light and save an area ahead of the players
  • 35254c4 Pregen: keep an empty dedicated server from pausing while it runs
  • 4cd1504 Pregen: report what a stalled band waits for, and requeue lost light
  • 1a39af6 /pregen: plan any radius at once, and skip a strip's rows outside the circle
  • 5e9d45b /pregen: off unless the server turns it on

📊 Changes

15 files changed (+778 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/command/tests.rs (+18 -0)
📝 crates/horizon-client/src/command/vanilla.rs (+62 -5)
📝 crates/horizon-client/src/game.rs (+4 -1)
📝 crates/horizon-client/src/game/commands.rs (+2 -0)
📝 crates/horizon-client/src/game/commands/extra.rs (+2 -0)
➕ crates/horizon-client/src/game/commands/pregen.rs (+276 -0)
📝 crates/horizon-client/src/game/commands/terrain_cmds.rs (+1 -1)
📝 crates/horizon-client/src/game/dedicated.rs (+11 -1)
📝 crates/horizon-client/src/game/levels.rs (+10 -3)
📝 crates/horizon-client/src/lib.rs (+1 -0)
➕ crates/horizon-client/src/pregen.rs (+191 -0)
📝 crates/horizon-client/src/streaming.rs (+149 -3)
📝 docs/README.md (+1 -0)
📝 docs/hosting.md (+3 -0)
➕ docs/pregeneration.md (+47 -0)

📄 Description

What and why

Server owners pre-generate worlds before players join, so nobody waits for chunks and the server doesn't lag. On Java this needs a plugin like Chunky. This adds a Horizon command that does it, in single player and on horizon-server.

/pregen start <radius> [square|circle] [<x> <z>]
/pregen status
/pregen pause | continue
/pregen cancel

The radius is in blocks. The centre is where you stand, or the world spawn from the console. Progress goes to the log and to the player who started it every 5 seconds: chunks done, chunks per second and time left. It needs permission level 2. Docs are in docs/pregeneration.md.

How it works

  • The area is cut into strips up to 256 chunks wide. A band of rows (about 1,000 chunks) sweeps each strip from north to south.
  • Streaming treats the band like a player's area. It generates the band and the rings around it that decoration and light need.
  • A row counts as done once its chunks are lit and post-processed. The band then moves on, and the rows behind it are saved and unloaded like any chunk players leave. Memory stays flat whatever the radius: the whole server peaked at about 1 GB for a radius of 2,500 blocks.
  • Decoration order is fixed row by row, so the same seed gives the same chunks however the work is spread over threads.
  • Between ticks the server waits for worker results and hands out the next jobs right away, instead of once per tick. A chunk goes through five jobs (generate, decorate, finish, light, save), and each needs its neighbours' earlier ones, so this keeps every worker busy.

Two more commits make it safe to leave running:

  • An empty dedicated server no longer pauses itself after pause-when-empty-seconds while /pregen runs. Before, a paused server stopped post-processing and the task waited forever.
  • If the band doesn't move for 30 seconds, the log says what its first row is waiting for, and light is queued again for unlit chunks whose neighbours are all loaded.

This is over the 500-line guideline. The task, the command and the streaming band only work together, so I kept them in one pull request.

Measured

This command doesn't make generation itself faster. It just keeps Horizon's generator busy over a whole area. The numbers below show what a server owner gets when they pre-generate with Horizon instead of a Java server with Chunky.

Same Apple M1 Pro (8 performance and 2 efficiency cores), same seed (1234), square around 0,0, chunks generated, lit and saved. Java 25 with Fabric 26.3 and Chunky 1.5.3, once as is and once with C2ME 0.4.2. Thread count: workers for Horizon, max.bg.threads for Java, plus globalExecutorParallelism for C2ME. Squares of radius 300 blocks for 1 and 2 threads, 800 for the rest. The Horizon numbers include the surface rule change from my other pull request.

Threads Horizon /pregen Java + Chunky Java + Chunky + C2ME Horizon vs Java Horizon vs C2ME
1 97 chunks/s 54 52 1.8× 1.9×
2 187 88 100 2.1× 1.9×
4 389 163 180 2.4× 2.2×
6 499 194 183 2.6× 2.7×
8 603 206 198 2.9× 3.0×
10 622 214 210 2.9× 3.0×

On this machine both Java setups level off at about 200 chunks per second from 4 to 6 threads up. Lighting runs on one thread in Java, and I didn't add ScalableLux, so a tuned Java server may get further.

Time for a 5,000 × 5,000 block map (97,969 chunks) at those best rates:

Time
Horizon /pregen about 2 min 40 s
Java + Chunky + C2ME about 7 min 45 s
Java + Chunky about 7 min 40 s

A real full run of that size with /pregen finished in 243 s on a busy machine (load average 17 to 21), with the server's memory peaking at about 1 GB.

Vanilla reference

Horizon-only: vanilla has no pre-generation command. It follows vanilla where it touches the game: chunks are generated, lit, post-processed (LevelChunk.postProcessGeneration) and saved through the normal chunk pipeline, and nothing in the save format changes.

Self-check

pr_ready (tools/pr_ready.py on device-591, against origin/main at 6a065fa48, 1 min 30 s)

Check Result
Scope ⚠️ 14 files, +653 −12; 621 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (26 s)
tests: horizon-client ✅ 1236 passed (58 s)
doc tests ✅ 0 passed (1 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
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 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/1805 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `pr/pregen` --- ### 📝 Commits (5) - [`1506c18`](https://github.com/horizon-rust/horizon/commit/1506c1808a2e5bd9bee4307090c09d111ad9e446) Add /pregen: generate, light and save an area ahead of the players - [`35254c4`](https://github.com/horizon-rust/horizon/commit/35254c4f0230580e5293146a5203022a3c54d027) Pregen: keep an empty dedicated server from pausing while it runs - [`4cd1504`](https://github.com/horizon-rust/horizon/commit/4cd1504513ab7c5f9c4bd326fa1e4913adb3147d) Pregen: report what a stalled band waits for, and requeue lost light - [`1a39af6`](https://github.com/horizon-rust/horizon/commit/1a39af6b623f3f12fc15ba609a016c2f4e4ea464) /pregen: plan any radius at once, and skip a strip's rows outside the circle - [`5e9d45b`](https://github.com/horizon-rust/horizon/commit/5e9d45bc9afe0bf91feb22e49a5232cb00f38287) /pregen: off unless the server turns it on ### 📊 Changes **15 files changed** (+778 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/command/tests.rs` (+18 -0) 📝 `crates/horizon-client/src/command/vanilla.rs` (+62 -5) 📝 `crates/horizon-client/src/game.rs` (+4 -1) 📝 `crates/horizon-client/src/game/commands.rs` (+2 -0) 📝 `crates/horizon-client/src/game/commands/extra.rs` (+2 -0) ➕ `crates/horizon-client/src/game/commands/pregen.rs` (+276 -0) 📝 `crates/horizon-client/src/game/commands/terrain_cmds.rs` (+1 -1) 📝 `crates/horizon-client/src/game/dedicated.rs` (+11 -1) 📝 `crates/horizon-client/src/game/levels.rs` (+10 -3) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) ➕ `crates/horizon-client/src/pregen.rs` (+191 -0) 📝 `crates/horizon-client/src/streaming.rs` (+149 -3) 📝 `docs/README.md` (+1 -0) 📝 `docs/hosting.md` (+3 -0) ➕ `docs/pregeneration.md` (+47 -0) </details> ### 📄 Description ## What and why Server owners pre-generate worlds before players join, so nobody waits for chunks and the server doesn't lag. On Java this needs a plugin like Chunky. This adds a Horizon command that does it, in single player and on `horizon-server`. ``` /pregen start <radius> [square|circle] [<x> <z>] /pregen status /pregen pause | continue /pregen cancel ``` The radius is in blocks. The centre is where you stand, or the world spawn from the console. Progress goes to the log and to the player who started it every 5 seconds: chunks done, chunks per second and time left. It needs permission level 2. Docs are in `docs/pregeneration.md`. **How it works** - The area is cut into strips up to 256 chunks wide. A band of rows (about 1,000 chunks) sweeps each strip from north to south. - Streaming treats the band like a player's area. It generates the band and the rings around it that decoration and light need. - A row counts as done once its chunks are lit and post-processed. The band then moves on, and the rows behind it are saved and unloaded like any chunk players leave. Memory stays flat whatever the radius: the whole server peaked at about 1 GB for a radius of 2,500 blocks. - Decoration order is fixed row by row, so the same seed gives the same chunks however the work is spread over threads. - Between ticks the server waits for worker results and hands out the next jobs right away, instead of once per tick. A chunk goes through five jobs (generate, decorate, finish, light, save), and each needs its neighbours' earlier ones, so this keeps every worker busy. Two more commits make it safe to leave running: - An empty dedicated server no longer pauses itself after `pause-when-empty-seconds` while `/pregen` runs. Before, a paused server stopped post-processing and the task waited forever. - If the band doesn't move for 30 seconds, the log says what its first row is waiting for, and light is queued again for unlit chunks whose neighbours are all loaded. This is over the 500-line guideline. The task, the command and the streaming band only work together, so I kept them in one pull request. ## Measured This command doesn't make generation itself faster. It just keeps Horizon's generator busy over a whole area. The numbers below show what a server owner gets when they pre-generate with Horizon instead of a Java server with Chunky. Same Apple M1 Pro (8 performance and 2 efficiency cores), same seed (1234), square around 0,0, chunks generated, lit and saved. Java 25 with Fabric 26.3 and Chunky 1.5.3, once as is and once with C2ME 0.4.2. Thread count: `workers` for Horizon, `max.bg.threads` for Java, plus `globalExecutorParallelism` for C2ME. Squares of radius 300 blocks for 1 and 2 threads, 800 for the rest. The Horizon numbers include the surface rule change from my other pull request. | Threads | Horizon `/pregen` | Java + Chunky | Java + Chunky + C2ME | Horizon vs Java | Horizon vs C2ME | |---|---|---|---|---|---| | 1 | 97 chunks/s | 54 | 52 | 1.8× | 1.9× | | 2 | 187 | 88 | 100 | 2.1× | 1.9× | | 4 | 389 | 163 | 180 | 2.4× | 2.2× | | 6 | 499 | 194 | 183 | 2.6× | 2.7× | | 8 | 603 | 206 | 198 | 2.9× | 3.0× | | 10 | 622 | 214 | 210 | 2.9× | 3.0× | On this machine both Java setups level off at about 200 chunks per second from 4 to 6 threads up. Lighting runs on one thread in Java, and I didn't add ScalableLux, so a tuned Java server may get further. Time for a 5,000 × 5,000 block map (97,969 chunks) at those best rates: | | Time | |---|---| | Horizon `/pregen` | about 2 min 40 s | | Java + Chunky + C2ME | about 7 min 45 s | | Java + Chunky | about 7 min 40 s | A real full run of that size with `/pregen` finished in 243 s on a busy machine (load average 17 to 21), with the server's memory peaking at about 1 GB. ## Vanilla reference Horizon-only: vanilla has no pre-generation command. It follows vanilla where it touches the game: chunks are generated, lit, post-processed (`LevelChunk.postProcessGeneration`) and saved through the normal chunk pipeline, and nothing in the save format changes. ## Self-check **pr_ready** (`tools/pr_ready.py` on device-591, against origin/main at 6a065fa48, 1 min 30 s) | Check | Result | | --- | --- | | Scope | ⚠️ 14 files, +653 −12; 621 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (26 s) | | tests: horizon-client | ✅ 1236 passed (58 s) | | doc tests | ✅ 0 passed (1 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 | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <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:14 +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#3777
No description provided.