[PR #6636] [MERGED] Receive path: read into one buffer in place, reuse one inflater, read the pipe in blocks #7004

Closed
opened 2026-11-03 06:31:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6636
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/net-recv-buffer


📝 Commits (1)

  • c53bea9 Receive path: one buffer read into in place, one inflater, block pipe reads

📊 Changes

2 files changed (+211 additions, -69 deletions)

View changed files

📝 crates/horizon-protocol/src/connection.rs (+114 -39)
📝 crates/horizon-protocol/src/frame.rs (+97 -30)

📄 Description

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

What

On the client, the receive path did three things for every packet: a copy of its frame out of the read buffer, a fresh zlib Decompress for each compressed packet, and a byte-by-byte copy out of the in-memory pipe (single player's server thread). This PR removes all three:

  • ConnReader keeps a start..end window in one buffer. It reads into the buffer's free tail in place (64 KiB at a time, more for a larger frame), decrypts only the new bytes, parses the frame header there, and moves start past the packet. It compacts only when it needs room.
  • One frame::Inflater per connection, reused with reset. It checks that the stream ends and that the size matches the declared one, as vanilla's CompressionDecoder does.
  • The pipe's read hands out whole VecDeque slices.

The wire format is unchanged (protocol 777). New tests check that packets of every size around the buffer and frame boundaries arrive whole, plain, compressed and encrypted, and that the inflater is reused across packets.

A/B (net_replay from #6436, AMD EPYC 7662, one core, alternated twice)

A Horizon dedicated server at RD 32, one join: 3725 chunks, 116k packets, 167 MB of bodies, 30.2 MB on the wire. The time is ConnReader::recv for every packet. Both sides include the hardware AES from #6437.

path before after
single player pipe (no compression) 341-343 ms 76-104 ms (3.3-4.5x)
compressed (threshold 256) 410-457 ms 275-311 ms (1.3-1.6x)
compressed + encrypted 436-555 ms 426-499 ms (noise)

Compared with main before #6437, the encrypted path went from 8.0-9.5 s to under 0.5 s.

Self-check

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 455b6916b, 66 min 33 s)

Check Result
Scope ⚠️ 453 files, +22734 −3027; 24685 lines of code: over 500, split it if it can ship in parts; mixes CI, game, launcher
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ✅ 595 passed (1 min 11 s)
rustfmt ✅ (13 s)
clippy ✅ (3 min 54 s)
tests: workspace ❌ 2100 passed (39 min 4 s)
doc tests ✅ 0 passed (15 s)
content root tests ✅ 22 passed (10 min 0 s)
tokens.css up to date ✅
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (4 min 0 s)
launcher tests ✅ 396 passed (7 min 52 s)
Parity ➖ 377 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 365 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Notes on this run:

  • The checkout's origin/main was stale (455b6916b), so the scope line counts unrelated files from main, and every crate's tests ran. This PR changes two files in horizon-protocol (+211 −69).
  • tests: workspace ❌ is the horizon-client-render lib test binary crashing with SIGSEGV in its GPU tests on playhorizon's llvmpipe (no GPU). The same crash shows up in other PRs' pr_ready there, it passes single-threaded, and this PR doesn't touch the crate. cargo stopped at that binary, so cargo test -p horizon-protocol was run separately on the Mac (M4 Pro): 160 passed, 0 failed. CI verify (the full workspace) passed.

🤖 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/6636 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/net-recv-buffer` --- ### 📝 Commits (1) - [`c53bea9`](https://github.com/horizon-rust/horizon/commit/c53bea9730cc3525335718e34cecff361ee62ee4) Receive path: one buffer read into in place, one inflater, block pipe reads ### 📊 Changes **2 files changed** (+211 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-protocol/src/connection.rs` (+114 -39) 📝 `crates/horizon-protocol/src/frame.rs` (+97 -30) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What On the client, the receive path did three things for every packet: a copy of its frame out of the read buffer, a fresh zlib `Decompress` for each compressed packet, and a byte-by-byte copy out of the in-memory pipe (single player's server thread). This PR removes all three: - `ConnReader` keeps a `start..end` window in one buffer. It reads into the buffer's free tail in place (64 KiB at a time, more for a larger frame), decrypts only the new bytes, parses the frame header there, and moves `start` past the packet. It compacts only when it needs room. - One `frame::Inflater` per connection, reused with `reset`. It checks that the stream ends and that the size matches the declared one, as vanilla's `CompressionDecoder` does. - The pipe's `read` hands out whole `VecDeque` slices. The wire format is unchanged (protocol 777). New tests check that packets of every size around the buffer and frame boundaries arrive whole, plain, compressed and encrypted, and that the inflater is reused across packets. ## A/B (`net_replay` from #6436, AMD EPYC 7662, one core, alternated twice) A Horizon dedicated server at RD 32, one join: 3725 chunks, 116k packets, 167 MB of bodies, 30.2 MB on the wire. The time is `ConnReader::recv` for every packet. Both sides include the hardware AES from #6437. | path | before | after | |---|---|---| | single player pipe (no compression) | 341-343 ms | 76-104 ms (**3.3-4.5x**) | | compressed (threshold 256) | 410-457 ms | 275-311 ms (**1.3-1.6x**) | | compressed + encrypted | 436-555 ms | 426-499 ms (noise) | Compared with main before #6437, the encrypted path went from 8.0-9.5 s to under 0.5 s. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 455b6916b, 66 min 33 s) | Check | Result | | --- | --- | | Scope | ⚠️ 453 files, +22734 −3027; 24685 lines of code: over 500, split it if it can ship in parts; mixes CI, game, launcher | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 595 passed (1 min 11 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (3 min 54 s) | | tests: workspace | ❌ 2100 passed (39 min 4 s) | | doc tests | ✅ 0 passed (15 s) | | content root tests | ✅ 22 passed (10 min 0 s) | | tokens.css up to date | ✅ | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (4 min 0 s) | | launcher tests | ✅ 396 passed (7 min 52 s) | | Parity | ➖ 377 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 365 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Notes on this run: - The checkout's `origin/main` was stale (455b6916b), so the scope line counts unrelated files from main, and every crate's tests ran. This PR changes two files in `horizon-protocol` (+211 −69). - `tests: workspace` ❌ is the `horizon-client-render` lib test binary crashing with SIGSEGV in its GPU tests on playhorizon's llvmpipe (no GPU). The same crash shows up in other PRs' pr_ready there, it passes single-threaded, and this PR doesn't touch the crate. cargo stopped at that binary, so `cargo test -p horizon-protocol` was run separately on the Mac (M4 Pro): 160 passed, 0 failed. CI `verify` (the full workspace) passed. 🤖 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 06:31:43 +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#7004
No description provided.