[PR #5020] [MERGED] Prepare the world beside the server thread's Game #6010

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

📋 Pull Request Information

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

Base: main ← Head: perf/server-thread-overlap


📝 Commits (1)

  • 5bda60a perf(server-thread): prepare the world beside the server's Game

📊 Changes

4 files changed (+94 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/game/dedicated.rs (+5 -0)
📝 crates/horizon-client/src/game/integrated.rs (+54 -13)
📝 crates/horizon-client/src/game/lan.rs (+34 -0)
📝 crates/horizon-client/src/game/native_lifecycle.rs (+1 -1)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally.

On the server thread, serve built the server's Game first, and only after that integrated_open ran WorldRequest::prepare and read the sync data, one after the other. Now serve starts the WorldLoader (prepare) and a read-ahead of the sync data before server_game. Both run while the Game is built. integrated_open then joins them: join_world_rest, then finish_open_world(opening.world?.finish()?), then sync.adopt(...).

  • game/integrated.rs: the new struct Opening { world, sync } is passed through run_integrated to integrated_open.
  • game/lan.rs: SyncPreload, the read-ahead thread. adopt uses its result only when the pack overlay has no files; otherwise the sync data is read as before.
  • game/dedicated.rs: the dedicated server does the same sync read-ahead.
  • native_lifecycle.rs: the test that checks the source now looks for the new finish_open_world line.

Ordering note: native mods' "open started" event now fires after prepare has begun its file work (creating the world, taking the session lock), no longer before it.

Before / after

How it was measured. --profile fast builds of this branch and of its base 37ad1f5c9 (main), run on the same machine (12 cores, RTX 4060, Linux, warm file cache). Runs are interleaved A/B with the order flipped every iteration, after 1 warm-up run. Every run gets fresh scratch homes. The numbers are medians. "Socket" is the time from spawn until the control socket answers (startup done). "World ready" is the time until horizon-ctl wait-ready returns (--offscreen --world W --creative --seed 1). "Reopen" opens a copy of a world made earlier; "new world" creates one. The async rows are the log timings of a plain launch with no control socket (the loading screen path). Other jobs were running on the machine (load 4–8), which is why the runs were interleaved.

Measure main this PR Difference
World ready, new world (10 runs) 4232 ms 3234 ms −998 ms (−23.6%)
World ready, reopen (12 runs) 2866 ms 2688 ms −178 ms (−6.2%)
Socket, reopen 1595 ms 1606 ms +11 ms (+0.7%, noise: startup is untouched)
Socket, new world 1575 ms 1589 ms +14 ms (+0.9%, noise)

New worlds gain the most, because there prepare does the most work (creating the world, picking a spawn).

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at 37ad1f5c9, 5 min 35 s)

Check Result
Scope ✅ 4 files, +94 −14
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed
rustfmt ✅
clippy ✅
tests: horizon-client ✅ 1318 passed
doc tests ✅ 0 passed
content root tests ➖ content root untouched
launcher ➖ launcher untouched
Parity ➖ affected harnesses run in CI (--quick)

Parity run locally: dedicated_server ✅, server_entities ✅.

Closes #5001

🤖 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/5020 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `perf/server-thread-overlap` --- ### 📝 Commits (1) - [`5bda60a`](https://github.com/horizon-rust/horizon/commit/5bda60aa5d8acee3f04007cbad378ce49bc23687) perf(server-thread): prepare the world beside the server's Game ### 📊 Changes **4 files changed** (+94 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/dedicated.rs` (+5 -0) 📝 `crates/horizon-client/src/game/integrated.rs` (+54 -13) 📝 `crates/horizon-client/src/game/lan.rs` (+34 -0) 📝 `crates/horizon-client/src/game/native_lifecycle.rs` (+1 -1) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. On the server thread, `serve` built the server's `Game` first, and only after that `integrated_open` ran `WorldRequest::prepare` and read the sync data, one after the other. Now `serve` starts the `WorldLoader` (prepare) and a read-ahead of the sync data before `server_game`. Both run while the `Game` is built. `integrated_open` then joins them: `join_world_rest`, then `finish_open_world(opening.world?.finish()?)`, then `sync.adopt(...)`. - `game/integrated.rs`: the new `struct Opening { world, sync }` is passed through `run_integrated` to `integrated_open`. - `game/lan.rs`: `SyncPreload`, the read-ahead thread. `adopt` uses its result only when the pack overlay has no files; otherwise the sync data is read as before. - `game/dedicated.rs`: the dedicated server does the same sync read-ahead. - `native_lifecycle.rs`: the test that checks the source now looks for the new `finish_open_world` line. **Ordering note:** native mods' "open started" event now fires after prepare has begun its file work (creating the world, taking the session lock), no longer before it. ## Before / after **How it was measured.** `--profile fast` builds of this branch and of its base `37ad1f5c9` (main), run on the same machine (12 cores, RTX 4060, Linux, warm file cache). Runs are interleaved A/B with the order flipped every iteration, after 1 warm-up run. Every run gets fresh scratch homes. The numbers are medians. "Socket" is the time from spawn until the control socket answers (startup done). "World ready" is the time until `horizon-ctl wait-ready` returns (`--offscreen --world W --creative --seed 1`). "Reopen" opens a copy of a world made earlier; "new world" creates one. The async rows are the log timings of a plain launch with no control socket (the loading screen path). Other jobs were running on the machine (load 4–8), which is why the runs were interleaved. | Measure | main | this PR | Difference | | --- | ---: | ---: | ---: | | World ready, new world (10 runs) | 4232 ms | 3234 ms | **−998 ms (−23.6%)** | | World ready, reopen (12 runs) | 2866 ms | 2688 ms | **−178 ms (−6.2%)** | | Socket, reopen | 1595 ms | 1606 ms | +11 ms (+0.7%, noise: startup is untouched) | | Socket, new world | 1575 ms | 1589 ms | +14 ms (+0.9%, noise) | New worlds gain the most, because there `prepare` does the most work (creating the world, picking a spawn). **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at 37ad1f5c9, 5 min 35 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +94 −14 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed | | rustfmt | ✅ | | clippy | ✅ | | tests: horizon-client | ✅ 1318 passed | | doc tests | ✅ 0 passed | | content root tests | ➖ content root untouched | | launcher | ➖ launcher untouched | | Parity | ➖ affected harnesses run in CI (--quick) | Parity run locally: `dedicated_server` ✅, `server_entities` ✅. Closes #5001 🤖 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:16:36 +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#6010
No description provided.