[PR #1181] [MERGED] Chunk packets get 1 ms a frame on a client of a server (RD 32 frame spikes) #3396

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

📋 Pull Request Information

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

Base: main ← Head: perf/spread-chunk-packets


📝 Commits (1)

  • 8291c8a Chunk packets get 1 ms a frame; the rest waits for the next frame

📊 Changes

2 files changed (+58 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game/control.rs (+1 -1)
📝 crates/horizon-client/src/game/remote.rs (+57 -6)

📄 Description

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

Part of #678 (reported by rickdickem on Discord). This is the last PR of the set: #1178 (spans), #1179 (render thread ahead), this one. It doesn't say Fixes #678: Linux is not measured yet (see below).

What

A client of a server (single player's server thread, LAN, multiplayer) handled every received packet in the frame it arrived. Now:

  • once a frame has spent 1 ms on chunk packets (LevelChunkWithLight), the events from the next chunk packet on wait for the next frame, in order;
  • events that have waited 50 ms (a tick) are all handled in the next frame, whatever they cost, so a slow machine's backlog never holds packets back longer than that;
  • the status's pending_chunks counts the waiting events, so horizon-ctl wait-ready still waits for every chunk.

Order is kept: nothing after a deferred chunk packet is handled before it. Vanilla handles every queued packet each frame. The only difference here is when a few packets are handled, at most a tick later.

Why

With #1179, the long frames left at render distance 32 were real work on the render thread. HORIZON_SPIKES (#1178) and a per-packet count showed it:

slow frame 10.4 ms, cpu 10.4 ms (0 ticks): update_world 9.5, poll_remote 8.0, streaming 1.5, renderer 0.8
poll 3.6 ms: LevelChunkWithLight ×30 3.44 ms, AddEntity ×19 0.06 ms, …

Each time the player crosses a chunk border at 32 chunks, the server sends a 65-column edge, 25 to 60 columns in a tick. Decoding them (remote_chunk: palettes, biomes, light) costs about 0.12 ms each on an M4 Pro, all in one frame. Those batches made up most of the frames between 5 and 10 ms.

Before / after

Setup:

  • Mac mini, M4 Pro, Metal, --offscreen.
  • Seed 1234, render distance 32, --server-thread, uncapped.
  • Raw frame times from horizon-ctl fly … raw.
  • Interleaved runs of the same base: main + #1179, with and without this change.
  • Run while the Mac mini was quiet (load average 6–12, no other game on the GPU).

Loaded terrain, back and forth over the village path, 3 runs of 4 × 12 s each:

p50 p99 p99.9 max frames > 10 ms per run
before 1.60–1.66 ms 3.28–3.30 ms 7.69–8.63 ms 12.0–17.0 ms 10–18
after 1.52–1.64 ms 3.11–3.19 ms 3.97–4.08 ms 11.3–17.0 ms 4–6

The render thread's own work per frame (frame time minus GPU and present waits), pooled:

p50 p99 p99.9 frames over 5 ms
before 0.81 ms 2.40 ms 7.04 ms 151 of 94,584
after 0.72 ms 2.27 ms 3.28 ms 8 of 95,965

Fresh terrain, a new world each run, 30 s over 480 blocks, 2 runs each:

p99 p99.9 max render-thread work p99.9
before 2.53–2.56 ms 5.65–6.24 ms 11.6–14.9 ms 4.61–4.63 ms
after 2.32–2.38 ms 4.60–5.02 ms 12.0–12.6 ms 3.25–3.43 ms

Chunk arrival: 10 s after the flight, all four runs had 3725 columns. At the end of the flight, three runs had 3715–3716 and one "after" run had 3661 with 120 events still waiting: it was caught right after a border crossing.

An earlier set, taken while another session's game was using the GPU, showed the same change in render-thread work (p99.9 8.7 → 3.6 ms). Its wall-clock frame times were dominated by that game's GPU load.

With the three PRs together, p99.9 at 32 chunks is now close to p99 on the Mac mini (4.0 against 3.2 ms; it was 38.5 against 14.4 ms on main).

Screenshot comparison

This changes when chunk packets are handled, not how anything draws. I took offscreen screenshots at a fixed spot after wait-ready (seed 1234, RD 12, --server-thread, so the chunks come through this path):

  • this branch against main: 55k and 295k of 922k pixels differ;
  • main against main: 324k differ (time of day, animated textures).

The difference is within the run-to-run noise, and the screenshots look the same.

How tested (Mac mini M4 Pro)

  • cargo fmt --all --check: ok

  • set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings: ok

  • cargo test -p horizon-client: all passed (985 lib, 91 bin, …).

  • tools/parity.py --changed origin/main, on one integration commit of #1178, #1179 and this PR: 102 passed, 0 failed. 78 passed in the first run (#1178 and #1179); this PR's commit reran 24, including dedicated_server, which passed on a fresh-oracle retry.

  • tools/lan_e2e.py --server-thread, full suite:

    passed failed
    main 47 1 (swings)
    this branch 47 1 (swings)

    swings is a known flake (FEATURES 4j(g) and 4l(d)). An earlier full run of this branch also failed sign and xp, both known flakes (FEATURES 4l(d)). Those two and swings all passed in a rerun of just those checks.

What is left (FEATURES.md LATER)

  • Linux: the render thread can't be raised there. Test whether the client's workers going behind it (behind_server) gives the same result, on the desktop.
  • The two worker pools of N−2 with the server thread (vanilla shares one pool of N−1).
  • The chunk decode itself (0.12 ms a column) could move off the render thread.

🤖 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/1181 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/spread-chunk-packets` --- ### 📝 Commits (1) - [`8291c8a`](https://github.com/horizon-rust/horizon/commit/8291c8af5b06f73cec102b7c88702ab2cda67ca6) Chunk packets get 1 ms a frame; the rest waits for the next frame ### 📊 Changes **2 files changed** (+58 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/control.rs` (+1 -1) 📝 `crates/horizon-client/src/game/remote.rs` (+57 -6) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of #678 (reported by **rickdickem** on Discord). This is the last PR of the set: #1178 (spans), #1179 (render thread ahead), this one. It doesn't say `Fixes #678`: Linux is not measured yet (see below). ## What A client of a server (single player's server thread, LAN, multiplayer) handled every received packet in the frame it arrived. Now: - once a frame has spent 1 ms on chunk packets (`LevelChunkWithLight`), the events from the next chunk packet on wait for the next frame, in order; - events that have waited 50 ms (a tick) are all handled in the next frame, whatever they cost, so a slow machine's backlog never holds packets back longer than that; - the status's `pending_chunks` counts the waiting events, so `horizon-ctl wait-ready` still waits for every chunk. Order is kept: nothing after a deferred chunk packet is handled before it. Vanilla handles every queued packet each frame. The only difference here is when a few packets are handled, at most a tick later. ## Why With #1179, the long frames left at render distance 32 were real work on the render thread. `HORIZON_SPIKES` (#1178) and a per-packet count showed it: ``` slow frame 10.4 ms, cpu 10.4 ms (0 ticks): update_world 9.5, poll_remote 8.0, streaming 1.5, renderer 0.8 poll 3.6 ms: LevelChunkWithLight ×30 3.44 ms, AddEntity ×19 0.06 ms, … ``` Each time the player crosses a chunk border at 32 chunks, the server sends a 65-column edge, 25 to 60 columns in a tick. Decoding them (`remote_chunk`: palettes, biomes, light) costs about 0.12 ms each on an M4 Pro, all in one frame. Those batches made up most of the frames between 5 and 10 ms. ## Before / after Setup: - Mac mini, M4 Pro, Metal, `--offscreen`. - Seed 1234, render distance 32, `--server-thread`, uncapped. - Raw frame times from `horizon-ctl fly … raw`. - Interleaved runs of the same base: `main` + #1179, with and without this change. - Run while the Mac mini was quiet (load average 6–12, no other game on the GPU). **Loaded terrain**, back and forth over the village path, 3 runs of 4 × 12 s each: | | p50 | p99 | p99.9 | max | frames > 10 ms per run | |---|---|---|---|---|---| | before | 1.60–1.66 ms | 3.28–3.30 ms | 7.69–8.63 ms | 12.0–17.0 ms | 10–18 | | after | 1.52–1.64 ms | 3.11–3.19 ms | **3.97–4.08 ms** | 11.3–17.0 ms | 4–6 | The render thread's own work per frame (frame time minus GPU and present waits), pooled: | | p50 | p99 | p99.9 | frames over 5 ms | |---|---|---|---|---| | before | 0.81 ms | 2.40 ms | 7.04 ms | 151 of 94,584 | | after | 0.72 ms | 2.27 ms | 3.28 ms | 8 of 95,965 | **Fresh terrain**, a new world each run, 30 s over 480 blocks, 2 runs each: | | p99 | p99.9 | max | render-thread work p99.9 | |---|---|---|---|---| | before | 2.53–2.56 ms | 5.65–6.24 ms | 11.6–14.9 ms | 4.61–4.63 ms | | after | 2.32–2.38 ms | 4.60–5.02 ms | 12.0–12.6 ms | 3.25–3.43 ms | Chunk arrival: 10 s after the flight, all four runs had 3725 columns. At the end of the flight, three runs had 3715–3716 and one "after" run had 3661 with 120 events still waiting: it was caught right after a border crossing. An earlier set, taken while another session's game was using the GPU, showed the same change in render-thread work (p99.9 8.7 → 3.6 ms). Its wall-clock frame times were dominated by that game's GPU load. With the three PRs together, p99.9 at 32 chunks is now close to p99 on the Mac mini (4.0 against 3.2 ms; it was 38.5 against 14.4 ms on `main`). ## Screenshot comparison This changes when chunk packets are handled, not how anything draws. I took offscreen screenshots at a fixed spot after `wait-ready` (seed 1234, RD 12, `--server-thread`, so the chunks come through this path): - this branch against `main`: 55k and 295k of 922k pixels differ; - `main` against `main`: 324k differ (time of day, animated textures). The difference is within the run-to-run noise, and the screenshots look the same. ## How tested (Mac mini M4 Pro) - `cargo fmt --all --check`: ok - `set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client`: all passed (985 lib, 91 bin, …). - `tools/parity.py --changed origin/main`, on one integration commit of #1178, #1179 and this PR: **102 passed, 0 failed**. 78 passed in the first run (#1178 and #1179); this PR's commit reran 24, including `dedicated_server`, which passed on a fresh-oracle retry. - `tools/lan_e2e.py --server-thread`, full suite: | | passed | failed | |---|---|---| | `main` | 47 | 1 (`swings`) | | this branch | 47 | 1 (`swings`) | `swings` is a known flake (FEATURES 4j(g) and 4l(d)). An earlier full run of this branch also failed `sign` and `xp`, both known flakes (FEATURES 4l(d)). Those two and `swings` all passed in a rerun of just those checks. ## What is left (FEATURES.md LATER) - Linux: the render thread can't be raised there. Test whether the client's workers going behind it (`behind_server`) gives the same result, on the desktop. - The two worker pools of N−2 with the server thread (vanilla shares one pool of N−1). - The chunk decode itself (0.12 ms a column) could move off the render thread. 🤖 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 04:09: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#3396
No description provided.