[PR #971] [MERGED] Chunk batches: make the columns' heightmaps on the warm-up threads too #2953

Closed
opened 2026-11-02 16:00:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/heightmaps-on-helpers


📝 Commits (1)

  • 3667bb9 Chunk batches: make the columns' heightmaps on the warm-up threads too

📊 Changes

3 files changed (+211 additions, -71 deletions)

View changed files

📝 crates/horizon-client/src/assets.rs (+20 -0)
📝 crates/horizon-client/src/lan/chunks.rs (+161 -60)
📝 crates/horizon-client/src/save.rs (+30 -11)

📄 Description

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

What

A chunk packet's heightmaps (WORLD_SURFACE, MOTION_BLOCKING, MOTION_BLOCKING_NO_LEAVES, Heightmap.primeHeightmaps over the column) are now made on the chunk-encode warm-up threads with the column's new sections, instead of on the server thread inside body_in:

  • ChunkEncoder::warm already shares a batch's uncached sections out to the warm-up threads (#934). Its job now lists the batch's columns whose heightmaps aren't cached yet first (each column once), then the sections. Whichever thread is free takes the next piece of work; the server thread takes work too and never waits.
  • What a helper finishes is cached under the column's sections, exactly as heightmaps() caches what it makes itself (keep_heights, the same sweep). body_in then finds it in the cache; a column a helper hadn't finished is made by body_in as before. The bytes can't differ: it is the same function over the same sections, and the cache is keyed by the sections' addresses, so an edited column never gets stale heightmaps.
  • save::client_heightmaps_in and its HeightmapView read a column's sections (&[Arc<Section>]) rather than a &Chunk, so a helper can work from the sections the job holds. The view reads blocks the way Chunk::get does (no block outside the sections).
  • warm is split into job (what to do), the hand-out, and keep (cache the results), so a test can run a job on one thread.

The packet order, the batches and PlayerChunkSender pacing are unchanged.

Why

Brief perf-server-11, task 2: heightmaps were the last part of a new column's packet still made on the server thread. Vanilla keeps them on the LevelChunk and copies them into the packet; Horizon computes them when the column is first sent, so this keeps the same values and moves the work where #934 already moved the sections.

Numbers

ThinkPad (Linux, 4 threads, where the helpers and the server share few cores), tools/server_bench.py --servers horizon --bots 1 --nice 19 under nice 19 and ionice -c3, HORIZON_SPIKES=0, each run redone if another job started on the machine. The span totals come from an experiment build with extra spans inside lan_chunks (not in this PR): bodies is the packet bodies made on the server thread, heightmaps the part of them spent on heightmaps. base = main with #915, #934, #914 and #927; new = base + this PR + the sculk PR.

1 bot, explore tick wall p50 / p99 / max (ms) lan_chunks total (s) bodies (s) heightmaps (s) MSPT avg / p95 / p99 chunks/s
base 1 7.6 / 38.8 / 66.6 6.7 1.3 0.6 10.4 / 27.5 / 43.7 41.1
base 2 7.1 / 39.3 / 109.6 6.6 1.5 0.7 10.0 / 28.1 / 47.1 42.1
new 1 7.0 / 41.4 / 95.2 5.8 0.5 – 9.9 / 27.1 / 48.7 42.0
new 2 7.1 / 39.3 / 68.0 5.8 0.4 – 10.0 / 27.8 / 44.0 42.1

The server thread spends 0.9 s less in lan_chunks over the same run (−13 %), and the bodies it still makes cost a third of what they did. The tick p99 and max don't move on the ThinkPad: its worst ticks are tick_blocks with a wall time far above their CPU time (109.6 ms wall for 13.4 ms CPU), which is server-ticks-2's area.

Mac mini (M4 Pro, 14 threads, 80–90 % busy with other sessions), tools/server_bench.py --servers horizon --bots 40 --behaviour explore --explore-speed 5 --warmup 30 --seconds 120, HORIZON_SPIKES=0, first 400 ticks skipped, runs alternated. Builds on main with #915, #934, #914 and #927; "before" has the server-thread PR, "after" adds this one.

40 bots, explore lan_chunks total (s) tick_lan total (s) tick wall p50 / p99 (ms) chunks/s
before 1 5.5 11.2 14.8 / 30.9 243.0
before 2 5.2 10.8 14.5 / 30.1 243.2
after 1 4.9 10.8 14.7 / 33.3 243.1
after 2 4.6 10.3 14.4 / 30.2 241.3

lan_chunks drops by 0.6 s over the run (−11 %) for the same chunks. The tick percentiles are within the noise between runs on this machine.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: 896 lib + 77 bin tests pass. warmed_columns_give_the_same_bodies now gives both encoders heightmap tables (air, stone, water and a sign with their heightmap facts), so its byte comparison covers the heightmaps; it also runs a job on the test thread alone and checks that it lists each column once (the duplicate column too), caches all 16 columns' heightmaps, and that the bodies then match a fresh encoder's.
  • Integration commit ae52589e (origin/main c569bbe2 + this PR + perf-server-11's other PRs and #968): parity chunk_stage, dedicated_server, heightmap, lan, sculk, server_entities, server_world_gen, world_reopen: 8 passed, 0 failed. lan_e2e with and without --server-thread: nothing fails that doesn't fail on main on the same machine (see #968 for the checks that are flaky on a busy Mac mini).

Doesn't touch game.rs tick order (server-ticks-2).

Needs Ludovic

Nothing.

🤖 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/971 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/heightmaps-on-helpers` --- ### 📝 Commits (1) - [`3667bb9`](https://github.com/horizon-rust/horizon/commit/3667bb963c63cca07f99182cc2da7c23a2977382) Chunk batches: make the columns' heightmaps on the warm-up threads too ### 📊 Changes **3 files changed** (+211 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/assets.rs` (+20 -0) 📝 `crates/horizon-client/src/lan/chunks.rs` (+161 -60) 📝 `crates/horizon-client/src/save.rs` (+30 -11) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What A chunk packet's heightmaps (WORLD_SURFACE, MOTION_BLOCKING, MOTION_BLOCKING_NO_LEAVES, `Heightmap.primeHeightmaps` over the column) are now made on the chunk-encode warm-up threads with the column's new sections, instead of on the server thread inside `body_in`: - `ChunkEncoder::warm` already shares a batch's uncached sections out to the warm-up threads (#934). Its job now lists the batch's columns whose heightmaps aren't cached yet first (each column once), then the sections. Whichever thread is free takes the next piece of work; the server thread takes work too and never waits. - What a helper finishes is cached under the column's sections, exactly as `heightmaps()` caches what it makes itself (`keep_heights`, the same sweep). `body_in` then finds it in the cache; a column a helper hadn't finished is made by `body_in` as before. The bytes can't differ: it is the same function over the same sections, and the cache is keyed by the sections' addresses, so an edited column never gets stale heightmaps. - `save::client_heightmaps_in` and its `HeightmapView` read a column's sections (`&[Arc<Section>]`) rather than a `&Chunk`, so a helper can work from the sections the job holds. The view reads blocks the way `Chunk::get` does (no block outside the sections). - `warm` is split into `job` (what to do), the hand-out, and `keep` (cache the results), so a test can run a job on one thread. The packet order, the batches and `PlayerChunkSender` pacing are unchanged. ## Why Brief perf-server-11, task 2: heightmaps were the last part of a new column's packet still made on the server thread. Vanilla keeps them on the `LevelChunk` and copies them into the packet; Horizon computes them when the column is first sent, so this keeps the same values and moves the work where #934 already moved the sections. ## Numbers ThinkPad (Linux, 4 threads, where the helpers and the server share few cores), `tools/server_bench.py --servers horizon --bots 1 --nice 19` under `nice 19` and `ionice -c3`, `HORIZON_SPIKES=0`, each run redone if another job started on the machine. The span totals come from an experiment build with extra spans inside `lan_chunks` (not in this PR): `bodies` is the packet bodies made on the server thread, `heightmaps` the part of them spent on heightmaps. base = main with #915, #934, #914 and #927; new = base + this PR + the sculk PR. | 1 bot, explore | tick wall p50 / p99 / max (ms) | `lan_chunks` total (s) | bodies (s) | heightmaps (s) | MSPT avg / p95 / p99 | chunks/s | |---|---|---|---|---|---|---| | base 1 | 7.6 / 38.8 / 66.6 | 6.7 | 1.3 | 0.6 | 10.4 / 27.5 / 43.7 | 41.1 | | base 2 | 7.1 / 39.3 / 109.6 | 6.6 | 1.5 | 0.7 | 10.0 / 28.1 / 47.1 | 42.1 | | new 1 | 7.0 / 41.4 / 95.2 | **5.8** | **0.5** | – | 9.9 / 27.1 / 48.7 | 42.0 | | new 2 | 7.1 / 39.3 / 68.0 | **5.8** | **0.4** | – | 10.0 / 27.8 / 44.0 | 42.1 | The server thread spends 0.9 s less in `lan_chunks` over the same run (−13 %), and the bodies it still makes cost a third of what they did. The tick p99 and max don't move on the ThinkPad: its worst ticks are `tick_blocks` with a wall time far above their CPU time (109.6 ms wall for 13.4 ms CPU), which is server-ticks-2's area. Mac mini (M4 Pro, 14 threads, 80–90 % busy with other sessions), `tools/server_bench.py --servers horizon --bots 40 --behaviour explore --explore-speed 5 --warmup 30 --seconds 120`, `HORIZON_SPIKES=0`, first 400 ticks skipped, runs alternated. Builds on main with #915, #934, #914 and #927; "before" has the server-thread PR, "after" adds this one. | 40 bots, explore | `lan_chunks` total (s) | `tick_lan` total (s) | tick wall p50 / p99 (ms) | chunks/s | |---|---|---|---|---| | before 1 | 5.5 | 11.2 | 14.8 / 30.9 | 243.0 | | before 2 | 5.2 | 10.8 | 14.5 / 30.1 | 243.2 | | after 1 | **4.9** | 10.8 | 14.7 / 33.3 | 243.1 | | after 2 | **4.6** | 10.3 | 14.4 / 30.2 | 241.3 | `lan_chunks` drops by 0.6 s over the run (−11 %) for the same chunks. The tick percentiles are within the noise between runs on this machine. ## Checks - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: 896 lib + 77 bin tests pass. `warmed_columns_give_the_same_bodies` now gives both encoders heightmap tables (air, stone, water and a sign with their heightmap facts), so its byte comparison covers the heightmaps; it also runs a job on the test thread alone and checks that it lists each column once (the duplicate column too), caches all 16 columns' heightmaps, and that the bodies then match a fresh encoder's. - Integration commit ae52589e (origin/main c569bbe2 + this PR + perf-server-11's other PRs and #968): parity `chunk_stage`, `dedicated_server`, `heightmap`, `lan`, `sculk`, `server_entities`, `server_world_gen`, `world_reopen`: 8 passed, 0 failed. lan_e2e with and without `--server-thread`: nothing fails that doesn't fail on main on the same machine (see #968 for the checks that are flaky on a busy Mac mini). Doesn't touch `game.rs` tick order (server-ticks-2). ## Needs Ludovic Nothing. 🤖 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 16:00:22 +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#2953
No description provided.