[PR #6421] [MERGED] Chunk encoder: sections' light layers are not kept once sent (−26 MB RSS) #6861

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

📋 Pull Request Information

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

Base: main ← Head: mem-chunk-light-layers


📝 Commits (1)

  • ff41750 Chunk encoder: sections' light layers are not kept once sent

📊 Changes

1 file changed (+59 additions, -21 deletions)

View changed files

📝 crates/horizon-client/src/lan/chunks.rs (+59 -21)

📄 Description

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

Part of #6418.

What

The server's chunk encoder (lan/chunks.rs, the integrated server, LAN hosts and the dedicated server) kept, for every resident section with varying light, its two light DataLayers (4 KiB, Layers) in its section cache for as long as the section stayed unchanged: on a world at render distance 12 the sampling heap profile had 28 MiB live in Layers::of (20 MiB from the warm-up threads, 8 MiB from light updates). Making them again is a repack of 4,096 bytes into two nibble arrays, about a microsecond, done once per send.

  • The layers the warm-up threads make for a batch are still handed to the bodies that send them, now taken (Option::take) instead of cloned, and nothing is stored when a body makes them itself. The encoded section bytes stay cached as before.
  • light_update made the layers of every section of the column and then kept the changed ones; it now makes only the changed sections'. Same packet.

Measured

How it was measured. Arch Linux (zen kernel), Ryzen 5 5600X (12 threads), 32 GB, RTX 4060 8 GB (Vulkan, NVIDIA 615.78), --profile fast, --offscreen 1280x720, fresh scratch homes per start, render distance 12. A start goes to the title screen, creates the perf_bench world (seed 1234, creative), waits for spawn to load, then teleports to and flies tools/perf_bench.py's village and forest paths (12 s each) and samples after each. Video memory: what nvidia-smi attributes to the process, and the game's own allocator totals (status: gpu_allocated_bytes / gpu_reserved_bytes); RSS from /proc/<pid>/status. Three alternated starts per build, medians (range in brackets); main = dea6dea98.

main this PR
live heap in Layers::of (sampling profiler, forest) 28 MiB ~0
RSS after the flights 1,476 [1,474-1,506] MB 1,451 [1,445-1,477] MB (−25)
anonymous RSS 1,169 [1,166-1,198] MB 1,143 [1,137-1,169] MB (−26)
average FPS over the flights 1,832 1,900

The kept layers scale with the sections the server holds, so the saving grows with view distance and with players spread out on a server.

Tests

  • light_updates_carry_the_changed_sections (new): a light update decoded from its bytes carries the changed section's layers only, with the right nibbles (light_update had no test).
  • cached_light_follows_edits now also sends the same unchanged column again and expects the same light (the hand-off was taken by the first send).
  • The other lan::chunks tests (warmed_columns_give_the_same_bodies...) pass unchanged.

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at 80dfb5f35, 6 min 9 s)

Check Result
Scope ✅ 2 files, +59 −21
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 594 passed (33 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 5 s)
tests: horizon-client-lib ✅ 1277 passed (4 min 16 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 375 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 363 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/6421 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mem-chunk-light-layers` --- ### 📝 Commits (1) - [`ff41750`](https://github.com/horizon-rust/horizon/commit/ff41750d060496a5a19ff2018565e8be8cfebe4e) Chunk encoder: sections' light layers are not kept once sent ### 📊 Changes **1 file changed** (+59 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/chunks.rs` (+59 -21) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. Part of #6418. ## What The server's chunk encoder (`lan/chunks.rs`, the integrated server, LAN hosts and the dedicated server) kept, for every resident section with varying light, its two light `DataLayer`s (4 KiB, `Layers`) in its section cache for as long as the section stayed unchanged: on a world at render distance 12 the sampling heap profile had 28 MiB live in `Layers::of` (20 MiB from the warm-up threads, 8 MiB from light updates). Making them again is a repack of 4,096 bytes into two nibble arrays, about a microsecond, done once per send. - The layers the warm-up threads make for a batch are still handed to the bodies that send them, now taken (`Option::take`) instead of cloned, and nothing is stored when a body makes them itself. The encoded section bytes stay cached as before. - `light_update` made the layers of every section of the column and then kept the changed ones; it now makes only the changed sections'. Same packet. ## Measured **How it was measured.** Arch Linux (zen kernel), Ryzen 5 5600X (12 threads), 32 GB, RTX 4060 8 GB (Vulkan, NVIDIA 615.78), `--profile fast`, `--offscreen` 1280x720, fresh scratch homes per start, render distance 12. A start goes to the title screen, creates the perf_bench world (seed 1234, creative), waits for spawn to load, then teleports to and flies `tools/perf_bench.py`'s village and forest paths (12 s each) and samples after each. Video memory: what `nvidia-smi` attributes to the process, and the game's own allocator totals (`status`: `gpu_allocated_bytes` / `gpu_reserved_bytes`); RSS from `/proc/<pid>/status`. Three alternated starts per build, medians (range in brackets); `main` = dea6dea98. | | main | this PR | |---|---|---| | live heap in `Layers::of` (sampling profiler, forest) | 28 MiB | ~0 | | RSS after the flights | 1,476 [1,474-1,506] MB | 1,451 [1,445-1,477] MB (−25) | | anonymous RSS | 1,169 [1,166-1,198] MB | 1,143 [1,137-1,169] MB (−26) | | average FPS over the flights | 1,832 | 1,900 | The kept layers scale with the sections the server holds, so the saving grows with view distance and with players spread out on a server. ## Tests - `light_updates_carry_the_changed_sections` (new): a light update decoded from its bytes carries the changed section's layers only, with the right nibbles (`light_update` had no test). - `cached_light_follows_edits` now also sends the same unchanged column again and expects the same light (the hand-off was taken by the first send). - The other `lan::chunks` tests (`warmed_columns_give_the_same_bodies`...) pass unchanged. **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at 80dfb5f35, 6 min 9 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +59 −21 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 594 passed (33 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 5 s) | | tests: horizon-client-lib | ✅ 1277 passed (4 min 16 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 375 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 363 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:28:16 +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#6861
No description provided.