[PR #545] [MERGED] Integrated server: join through memory instead of a socket #2631

Closed
opened 2026-11-02 15:57:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/integrated-memory-connection


📝 Commits (4)

  • c57c409 Split Resources into shared read-only data and per-game pack state
  • c2f4ecc Build the game in Game::new instead of inside run()
  • 56dc435 Run single player on an integrated server thread (opt-in)
  • db45b6f Integrated server: join through memory instead of a socket

📊 Changes

109 files changed (+1638 additions, -944 deletions)

View changed files

📝 crates/horizon-client/src/control.rs (+12 -8)
📝 crates/horizon-client/src/fog.rs (+0 -16)
📝 crates/horizon-client/src/game.rs (+526 -456)
📝 crates/horizon-client/src/game/advancements.rs (+5 -5)
📝 crates/horizon-client/src/game/advancements_screen.rs (+9 -9)
📝 crates/horizon-client/src/game/agent.rs (+1 -1)
📝 crates/horizon-client/src/game/armor_stands.rs (+5 -5)
📝 crates/horizon-client/src/game/backdrop.rs (+4 -4)
📝 crates/horizon-client/src/game/beacon.rs (+5 -11)
📝 crates/horizon-client/src/game/beehives.rs (+2 -2)
📝 crates/horizon-client/src/game/block_entity_anims.rs (+1 -1)
📝 crates/horizon-client/src/game/block_items.rs (+1 -1)
📝 crates/horizon-client/src/game/blockctl.rs (+3 -3)
📝 crates/horizon-client/src/game/boats.rs (+0 -1)
📝 crates/horizon-client/src/game/books.rs (+4 -4)
📝 crates/horizon-client/src/game/cartography.rs (+3 -3)
📝 crates/horizon-client/src/game/chat.rs (+14 -16)
📝 crates/horizon-client/src/game/command_blocks.rs (+7 -7)
📝 crates/horizon-client/src/game/commands.rs (+8 -8)
📝 crates/horizon-client/src/game/commands/compute.rs (+1 -1)

...and 80 more files

📄 Description

What and why

With #544, the window joins its integrated server over a TCP socket on 127.0.0.1. Vanilla doesn't use a socket for that: Connection.connectToLocalServer joins through Netty's in-process LocalChannel, and the integrated server opens no port until it is opened to the LAN. This PR does the same.

  • horizon-protocol: Connection runs over TCP or over one end of a new Pipe. A Pipe is a blocking in-memory byte pipe (mutex, condvar and a byte queue each way) with read timeouts and shutdown, and dropping an end closes it. Readers and writers keep the same API, so the packet code doesn't know which one it is talking to.
  • Lan: NetConfig.listen: false starts no listener. connect_local() serves the other end of a pipe on its own thread, through the same handshake, login and configuration code as a socket (serve_connection).
  • Client: Session::connect_local joins through a pipe. The connection screen's extras and the crash report's "Server" line are skipped for it.
  • Integrated server: it starts with listen: false, hands the window a pipe once the world is open, and no longer compresses (vanilla doesn't compress memory connections either).

Vanilla reference

  • Connection.connectToLocalServer
  • ServerConnectionListener.startMemoryChannel (LocalAddress, LocalServerChannel)
  • ServerLoginPacketListenerImpl: compression is set up only for non-memory connections

Harnesses: dedicated_server covers the socket path, which keeps its code. The opt-in memory path was checked with the smoke run in #544, which ran on this commit. New unit tests: local_pipe_carries_packets_and_closes, dropping_a_pipe_end_closes_it and local_pipe_read_times_out.

Measurements

The tables in #544 were measured on this commit. I didn't measure TCP against memory separately. At about 150 mobs' worth of entity packets, both cost little next to the frame. The visible changes: no port is opened, and the server log shows the player at /127.0.0.1:0.

Checks

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-protocol: 49 passed (3 new)
  • cargo test -p horizon-client --lib: 759 passed, 0 failed, 7 ignored
  • Local parity on this commit (the top of the stack): 84 passed, 0 failed (includes dedicated_server, lan, save_roundtrip, world_reopen and every single-player harness), on the stack rebased on main at a08add23

Stack: #537 → #538 → #544 → this PR.

Refs #495

🤖 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/545 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/integrated-memory-connection` --- ### 📝 Commits (4) - [`c57c409`](https://github.com/horizon-rust/horizon/commit/c57c409f40cb7a7b1e6939e0c61476a5134d9411) Split Resources into shared read-only data and per-game pack state - [`c2f4ecc`](https://github.com/horizon-rust/horizon/commit/c2f4ecc188d8fa49909550c4ab61eef85e75be7e) Build the game in Game::new instead of inside run() - [`56dc435`](https://github.com/horizon-rust/horizon/commit/56dc4352d2d935b8b199ea40baa8256bb41a6301) Run single player on an integrated server thread (opt-in) - [`db45b6f`](https://github.com/horizon-rust/horizon/commit/db45b6f87a4bf1e03ec3cc415faefaabde9480e5) Integrated server: join through memory instead of a socket ### 📊 Changes **109 files changed** (+1638 additions, -944 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/control.rs` (+12 -8) 📝 `crates/horizon-client/src/fog.rs` (+0 -16) 📝 `crates/horizon-client/src/game.rs` (+526 -456) 📝 `crates/horizon-client/src/game/advancements.rs` (+5 -5) 📝 `crates/horizon-client/src/game/advancements_screen.rs` (+9 -9) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -1) 📝 `crates/horizon-client/src/game/armor_stands.rs` (+5 -5) 📝 `crates/horizon-client/src/game/backdrop.rs` (+4 -4) 📝 `crates/horizon-client/src/game/beacon.rs` (+5 -11) 📝 `crates/horizon-client/src/game/beehives.rs` (+2 -2) 📝 `crates/horizon-client/src/game/block_entity_anims.rs` (+1 -1) 📝 `crates/horizon-client/src/game/block_items.rs` (+1 -1) 📝 `crates/horizon-client/src/game/blockctl.rs` (+3 -3) 📝 `crates/horizon-client/src/game/boats.rs` (+0 -1) 📝 `crates/horizon-client/src/game/books.rs` (+4 -4) 📝 `crates/horizon-client/src/game/cartography.rs` (+3 -3) 📝 `crates/horizon-client/src/game/chat.rs` (+14 -16) 📝 `crates/horizon-client/src/game/command_blocks.rs` (+7 -7) 📝 `crates/horizon-client/src/game/commands.rs` (+8 -8) 📝 `crates/horizon-client/src/game/commands/compute.rs` (+1 -1) _...and 80 more files_ </details> ### 📄 Description ## What and why With #544, the window joins its integrated server over a TCP socket on 127.0.0.1. Vanilla doesn't use a socket for that: `Connection.connectToLocalServer` joins through Netty's in-process `LocalChannel`, and the integrated server opens no port until it is opened to the LAN. This PR does the same. - **horizon-protocol**: `Connection` runs over TCP or over one end of a new `Pipe`. A `Pipe` is a blocking in-memory byte pipe (mutex, condvar and a byte queue each way) with read timeouts and shutdown, and dropping an end closes it. Readers and writers keep the same API, so the packet code doesn't know which one it is talking to. - **Lan**: `NetConfig.listen: false` starts no listener. `connect_local()` serves the other end of a pipe on its own thread, through the same handshake, login and configuration code as a socket (`serve_connection`). - **Client**: `Session::connect_local` joins through a pipe. The connection screen's extras and the crash report's "Server" line are skipped for it. - **Integrated server**: it starts with `listen: false`, hands the window a pipe once the world is open, and no longer compresses (vanilla doesn't compress memory connections either). ## Vanilla reference - `Connection.connectToLocalServer` - `ServerConnectionListener.startMemoryChannel` (`LocalAddress`, `LocalServerChannel`) - `ServerLoginPacketListenerImpl`: compression is set up only for non-memory connections Harnesses: `dedicated_server` covers the socket path, which keeps its code. The opt-in memory path was checked with the smoke run in #544, which ran on this commit. New unit tests: `local_pipe_carries_packets_and_closes`, `dropping_a_pipe_end_closes_it` and `local_pipe_read_times_out`. ## Measurements The tables in #544 were measured on this commit. I didn't measure TCP against memory separately. At about 150 mobs' worth of entity packets, both cost little next to the frame. The visible changes: no port is opened, and the server log shows the player at `/127.0.0.1:0`. ## Checks - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-protocol`: 49 passed (3 new) - `cargo test -p horizon-client --lib`: 759 passed, 0 failed, 7 ignored - Local parity on this commit (the top of the stack): 84 passed, 0 failed (includes `dedicated_server`, `lan`, `save_roundtrip`, `world_reopen` and every single-player harness), on the stack rebased on main at a08add23 Stack: #537 → #538 → #544 → this PR. Refs #495 🤖 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-02 15:57:48 +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#2631
No description provided.