[PR #3250] [MERGED] Server: feed the chunk workers between ticks while players' chunks load #4863

Closed
opened 2026-11-03 05:08:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/world-entry-pump-between-ticks


📝 Commits (1)

  • 7a84c93 Server: feed the chunk workers between ticks while players' chunks load

📊 Changes

3 files changed (+15 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game/commands/pregen.rs (+11 -3)
📝 crates/horizon-client/src/game/levels.rs (+3 -3)
📝 docs/pregeneration.md (+1 -1)

📄 Description

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

Roadmap item world-entry (faster world creation and entry on small CPUs).

What was slow

Joining a world on the server thread (single player's default, LAN hosts, dedicated servers) filled the view at
about 6 columns a tick. A sample of a reload with 2 workers showed both server workers in cvwait 93% of the
time and the server thread asleep 93% of the time, while columns trickled in at ~120/s.

The server thread runs streaming.update once per 50 ms tick, and schedule_generation keeps at most three
load or generate jobs per worker in flight (workers * 3). Each tick the workers finished their few jobs in a few
milliseconds and then waited for the next tick. Vanilla's server doesn't wait like that: it runs its chunk tasks
while it waits for the next tick (MinecraftServer.waitUntilNextTick → managedBlock).

The change

pump_pregen (renamed pump_chunks) already pumped the workers between ticks for a /pregen task and for
force-loaded chunks: it waits on Streaming::wait and runs update_world as each job finishes. Now it also pumps
while the players' chunks are in flight (streaming.busy()), except:

  • while the server is paused (an integrated server behind the pause menu, a held agent fixture);
  • while a respawn search waits for a chunk (spawn_wait): that area is only asked for by the tick's own
    update_world, and a pump update without it could drop it.

Nothing about what is generated changes: decoration runs in DecorationOrder's order whatever the timing (the
same mechanism /pregen and forced chunks already relied on). Chunk sending still runs once a tick, at vanilla's
pace (PlayerChunkSender).

Numbers

Mac mini M4 Pro, --profile fast, --offscreen, seed 1234, RD 12, server thread (default), the worker pool
capped with horizon-graphics.txt workers:N to stand in for a small CPU. Create = open World 1234 creative
in a fresh home; reload = quit, start again, open World. Fresh mktemp -d for HORIZON_HOME,
HORIZON_LAUNCHER_HOME, XDG_DATA_HOME, XDG_CONFIG_HOME, HORIZON_NO_AUDIO=1. Runs alternated main/branch;
medians of 3. "Terrain" = all 637 view columns received and every streaming stage drained the first time.

main this PR
2 workers, create: terrain 8.05 s (8.02, 8.05, 8.29) 3.57 s (3.37, 3.57, 3.62)
2 workers, reload: terrain 3.72 s (3.67, 3.72, 3.73) 1.42 s (1.41, 1.42, 1.59)
2 workers, create: first section meshed 1.62 s 1.17 s
4 workers, create: terrain 4.97 s (4.92, 4.97, 5.00) 2.16 s (2.15, 2.16, 2.84)
4 workers, reload: terrain 2.23 s (2.21, 2.23, 2.28) 1.27 s (1.20, 1.27, 1.30)
controllable (PlayerLoaded sent), all cases 0.9–1.2 s 0.9–1.2 s (unchanged)

Checks

pr_ready (tools/pr_ready.py on ludovics-mac-mini, against origin/main at cba52f4e5, 23 min 12 s)

Check Result
Scope ✅ 3 files, +15 −7
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 401 passed (45 s)
rustfmt ✅ (6 s)
clippy ✅ (2 min 21 s)
tests: horizon-client ✅ 1261 passed (3 min 50 s)
doc tests ✅ 0 passed (1 min 0 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 34 affected, 33 passed (15 min 6 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The one affected harness not run is lan_integration (the whole lan_e2e suite, by name only); tools/lan_e2e.py --check spawned respawn worldspawn distance portals forced-levels chest (host on its server thread): all 7 pass.

🤖 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/3250 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/world-entry-pump-between-ticks` --- ### 📝 Commits (1) - [`7a84c93`](https://github.com/horizon-rust/horizon/commit/7a84c938436060608d35a7e4589e069ada3030e8) Server: feed the chunk workers between ticks while players' chunks load ### 📊 Changes **3 files changed** (+15 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands/pregen.rs` (+11 -3) 📝 `crates/horizon-client/src/game/levels.rs` (+3 -3) 📝 `docs/pregeneration.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Roadmap item `world-entry` (faster world creation and entry on small CPUs). ## What was slow Joining a world on the server thread (single player's default, LAN hosts, dedicated servers) filled the view at about 6 columns a tick. A `sample` of a reload with 2 workers showed both server workers in `cvwait` 93% of the time and the server thread asleep 93% of the time, while columns trickled in at ~120/s. The server thread runs `streaming.update` once per 50 ms tick, and `schedule_generation` keeps at most three load or generate jobs per worker in flight (`workers * 3`). Each tick the workers finished their few jobs in a few milliseconds and then waited for the next tick. Vanilla's server doesn't wait like that: it runs its chunk tasks while it waits for the next tick (`MinecraftServer.waitUntilNextTick` → `managedBlock`). ## The change `pump_pregen` (renamed `pump_chunks`) already pumped the workers between ticks for a `/pregen` task and for force-loaded chunks: it waits on `Streaming::wait` and runs `update_world` as each job finishes. Now it also pumps while the players' chunks are in flight (`streaming.busy()`), except: - while the server is paused (an integrated server behind the pause menu, a held agent fixture); - while a respawn search waits for a chunk (`spawn_wait`): that area is only asked for by the tick's own `update_world`, and a pump update without it could drop it. Nothing about what is generated changes: decoration runs in `DecorationOrder`'s order whatever the timing (the same mechanism /pregen and forced chunks already relied on). Chunk sending still runs once a tick, at vanilla's pace (`PlayerChunkSender`). ## Numbers Mac mini M4 Pro, `--profile fast`, `--offscreen`, seed 1234, RD 12, server thread (default), the worker pool capped with `horizon-graphics.txt` `workers:N` to stand in for a small CPU. Create = `open World 1234 creative` in a fresh home; reload = quit, start again, `open World`. Fresh `mktemp -d` for `HORIZON_HOME`, `HORIZON_LAUNCHER_HOME`, `XDG_DATA_HOME`, `XDG_CONFIG_HOME`, `HORIZON_NO_AUDIO=1`. Runs alternated main/branch; medians of 3. "Terrain" = all 637 view columns received and every streaming stage drained the first time. | | main | this PR | |---|---|---| | 2 workers, create: terrain | 8.05 s (8.02, 8.05, 8.29) | **3.57 s** (3.37, 3.57, 3.62) | | 2 workers, reload: terrain | 3.72 s (3.67, 3.72, 3.73) | **1.42 s** (1.41, 1.42, 1.59) | | 2 workers, create: first section meshed | 1.62 s | 1.17 s | | 4 workers, create: terrain | 4.97 s (4.92, 4.97, 5.00) | **2.16 s** (2.15, 2.16, 2.84) | | 4 workers, reload: terrain | 2.23 s (2.21, 2.23, 2.28) | **1.27 s** (1.20, 1.27, 1.30) | | controllable (PlayerLoaded sent), all cases | 0.9–1.2 s | 0.9–1.2 s (unchanged) | ## Checks **pr_ready** (`tools/pr_ready.py` on ludovics-mac-mini, against origin/main at cba52f4e5, 23 min 12 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +15 −7 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 401 passed (45 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (2 min 21 s) | | tests: horizon-client | ✅ 1261 passed (3 min 50 s) | | doc tests | ✅ 0 passed (1 min 0 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 34 affected, 33 passed (15 min 6 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The one affected harness not run is `lan_integration` (the whole lan_e2e suite, by name only); `tools/lan_e2e.py --check spawned respawn worldspawn distance portals forced-levels chest` (host on its server thread): all 7 pass. 🤖 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 05:08:28 +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#4863
No description provided.