[PR #5793] [MERGED] Chunk sending: encode a section from its stored palette ids #6500

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

📋 Pull Request Information

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

Base: main ← Head: perf/chunk-encode-palette-ids


📝 Commits (1)

  • 6d035f2 Chunk sending: encode a section from its stored palette ids

📊 Changes

3 files changed (+122 additions, -18 deletions)

View changed files

📝 crates/horizon-client/src/lan/chunks.rs (+89 -15)
📝 crates/horizon-core/src/paletted.rs (+19 -0)
📝 crates/horizon-protocol/src/chunk.rs (+14 -3)

📄 Description

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

Sending chunks is mostly the first encoding of new sections (ChunkEncoder::warm, shared between the tick thread and the warm-up threads). A 20-bot profile (macOS sample, 40 s) puts SectionCoder::wire at 86 % of that work. Most of it went to taking the section apart and rebuilding it:

  1. section.unpack resolves all 4,096 stored palette ids into block states.
  2. Paletted::from_values builds a palette back from those values, first-seen order, through a table over the whole state range.

For a section with a list palette (every non-uniform section below 9 bits), the stored ids are now renumbered in first-seen order directly (network_palette). This gives the same palette and the same indices as from_values, without the 4,096 values. The block and fluid counts use one count per stored id, and the block-entity scan runs only when the palette holds a block entity. Uniform and global-palette sections take the paths they took before.

  • horizon-core: PalettedContainer::unpack_ids, the stored ids and the list they index.
  • horizon-protocol: Paletted::from_palette, the end of from_values (bit width, packing). from_values now calls it, so both paths pack the same way.
  • lan/chunks.rs: the fast path in SectionCoder::section, plus a test: random stored palettes, with a value held twice and ids no entry uses, give exactly Paletted::from_values' result.

The bytes sent are unchanged.

Measurement

playhorizon (EPYC, CPUs 0-3, exclusive), server_bench.py horizon, 20 mixed bots, 3 alternated rounds. Base is main 04029578c, test is this PR. The warm-up threads' share doesn't show in MSPT.

ms/tick round 1 round 2 round 3 median
tick_lan, main 4.21 4.33 4.22 4.22
tick_lan, this PR 4.10 3.94 3.96 3.96 (−6 %)
MSPT, main 25.65 26.39 25.49 25.65
MSPT, this PR 25.99 25.08 25.32 25.32

Checks

This PR touches horizon-core, so pr_ready tests the whole workspace. Because the Mac mini's disk was nearly full, the checks ran in two places:

  • Mac mini:
    • cargo fmt --all --check: pass.
    • cargo clippy -p horizon-core -p horizon-protocol -p horizon-client --lib --bins --tests -D warnings: pass.
  • playhorizon, pr_ready --quick (its toolchain has no clippy or rustfmt, and its origin/main was stale, which made the scope line wrong):
    • workspace tests: 3982 passed;
    • content root tests: 20 passed;
    • launcher tests: pass;
    • Python tests: 509 passed, 2 failed. test_lab ... start_no_virtual_screen fails because that machine's shell sets VSCREEN; the same tests pass on the Mac mini.
  • Targeted tests on playhorizon: paletted (horizon-core), horizon-protocol (157), lan::chunks (15, the new test included).
  • CI runs the affected harnesses (run-parity).

🤖 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/5793 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/chunk-encode-palette-ids` --- ### 📝 Commits (1) - [`6d035f2`](https://github.com/horizon-rust/horizon/commit/6d035f2fa194d88e3a42971e39a907e6ab2ea924) Chunk sending: encode a section from its stored palette ids ### 📊 Changes **3 files changed** (+122 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/chunks.rs` (+89 -15) 📝 `crates/horizon-core/src/paletted.rs` (+19 -0) 📝 `crates/horizon-protocol/src/chunk.rs` (+14 -3) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Sending chunks is mostly the first encoding of new sections (`ChunkEncoder::warm`, shared between the tick thread and the warm-up threads). A 20-bot profile (macOS `sample`, 40 s) puts `SectionCoder::wire` at 86 % of that work. Most of it went to taking the section apart and rebuilding it: 1. `section.unpack` resolves all 4,096 stored palette ids into block states. 2. `Paletted::from_values` builds a palette back from those values, first-seen order, through a table over the whole state range. For a section with a list palette (every non-uniform section below 9 bits), the stored ids are now renumbered in first-seen order directly (`network_palette`). This gives the same palette and the same indices as `from_values`, without the 4,096 values. The block and fluid counts use one count per stored id, and the block-entity scan runs only when the palette holds a block entity. Uniform and global-palette sections take the paths they took before. - `horizon-core`: `PalettedContainer::unpack_ids`, the stored ids and the list they index. - `horizon-protocol`: `Paletted::from_palette`, the end of `from_values` (bit width, packing). `from_values` now calls it, so both paths pack the same way. - `lan/chunks.rs`: the fast path in `SectionCoder::section`, plus a test: random stored palettes, with a value held twice and ids no entry uses, give exactly `Paletted::from_values`' result. The bytes sent are unchanged. ### Measurement playhorizon (EPYC, CPUs 0-3, exclusive), `server_bench.py` horizon, 20 mixed bots, 3 alternated rounds. Base is main 04029578c, test is this PR. The warm-up threads' share doesn't show in MSPT. | ms/tick | round 1 | round 2 | round 3 | median | |---|---|---|---|---| | `tick_lan`, main | 4.21 | 4.33 | 4.22 | 4.22 | | `tick_lan`, this PR | 4.10 | 3.94 | 3.96 | **3.96 (−6 %)** | | MSPT, main | 25.65 | 26.39 | 25.49 | 25.65 | | MSPT, this PR | 25.99 | 25.08 | 25.32 | 25.32 | ### Checks This PR touches horizon-core, so pr_ready tests the whole workspace. Because the Mac mini's disk was nearly full, the checks ran in two places: - **Mac mini:** - `cargo fmt --all --check`: pass. - `cargo clippy -p horizon-core -p horizon-protocol -p horizon-client --lib --bins --tests -D warnings`: pass. - **playhorizon**, `pr_ready --quick` (its toolchain has no clippy or rustfmt, and its `origin/main` was stale, which made the scope line wrong): - workspace tests: 3982 passed; - content root tests: 20 passed; - launcher tests: pass; - Python tests: 509 passed, 2 failed. `test_lab ... start_no_virtual_screen` fails because that machine's shell sets `VSCREEN`; the same tests pass on the Mac mini. - **Targeted tests on playhorizon:** paletted (horizon-core), horizon-protocol (157), lan::chunks (15, the new test included). - CI runs the affected harnesses (run-parity). 🤖 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:21:40 +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#6500
No description provided.