[PR #353] [MERGED] Save proto chunks on a worker, not the main thread #2513

Closed
opened 2026-11-02 15:56:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/proto-save-off-main


📝 Commits (1)

  • 1b46810 Save proto chunks on a worker, not the main thread (#224)

📊 Changes

2 files changed (+75 additions, -16 deletions)

View changed files

📝 crates/horizon-client/src/streaming.rs (+69 -16)
📝 crates/horizon-client/tests/generation_saves.rs (+6 -0)

📄 Description

Fixes #224 (the last hitch, left open by #300)

What

Proto chunks that decoration wrote to are now saved by a worker thread, not the main thread: both at the autosave and, while exploring, as they unload behind the player.

Why

#300 noted the remaining hitch: Streaming::save converted every written proto chunk on the main thread during the autosave (VanillaTerrain::saved_proto → column(), a block-by-block copy of the whole proto into a column, then the NBT encoding). The same conversion also ran on the main thread in Streaming::update, for every written proto unloaded behind the player, so it hit frames all through exploration, not only at the autosave. Vanilla's autosave hands its chunks to the IOWorker too.

How

The protos are checked out of Streaming::protos (set to None), as a decoration job already does, and sent as a Job::Save that runs ahead of every other job (so a column generated again meanwhile finds them saved). The worker calls ChunkGenerator::save_protos and hands them back (Done::Saved). While a proto is checked out, nothing can decorate or finish it, and generation doesn't ask for it again. A returned proto now out of range is dropped by the next update (it is no longer marked written).

  • Autosave (save(wait: false)): check out the written protos and return.
  • Explicit save, save-all, quitting, dimension change (save(wait: true)): wait for the decorations, finishing columns and saves in flight, then save in place, before the world's chunks, as before.
  • Dropping the streamer waits for the saves in flight (they hold protos nothing else would save).

Measurements

Mac mini M4 Pro, RD16, PerfBench world (seed 1234), offscreen. As in #300: open the world, then 30 s before the 5-minute autosave (tick 6000), teleport to new terrain (x 20000) and fly +x at 20 blocks/s for 60 s (horizon-ctl fly … raw), so decoration writes protos all along and the autosave finds many of them.

Main-thread time, measured with temporary timers around Streaming::save in the autosave and around Streaming::update (not in this PR), two games per build:

main this PR
Streaming::save in the autosave 178 ms, 371 ms 0.01 ms, 0.01 ms
slowest Streaming::update during the 60 s flight 263 ms, 738 ms 55 ms, 67 ms
explicit save at quit (waits, as before) 173 ms, 310 ms 132 ms, 155 ms

Frame times over the flight, five games per build (the two above and three without timers), means with 95% CIs (Student's t):

main this PR
worst frame within 2 s of the autosave 292 ± 197 ms 113 ± 62 ms
worst frame elsewhere in the flight 241 ± 108 ms 172 ± 66 ms
p99 frame 115 ± 108 ms 57 ± 34 ms

Other sessions were compiling on the Mac mini throughout (load average up to ~80), which is why the frame times are wide; the main-thread timers above are the clean signal. The 55–67 ms left in Streaming::update is other streaming work, not saving (a follow-up).

How tested

cargo fmt --all -- --check                                   OK
cargo clippy --workspace --all-targets -- -D warnings        OK
cargo test -p horizon-client                                 all passed
  generation_saves::chunks_left_behind_keep_their_decoration now autosaves (no wait) after each step of the walk
  and after the far teleport, then comes back: every column is still finished exactly once with all its
  neighbours' decoration
parity.py --changed origin/main                         80 passed, 0 failed (one run on the merge
                                                             of this PR with its three siblings: #270 relight
                                                             remesh, #224 proto saves, #271 frame cap, spawn
                                                             heightmap; includes section_mesh, light, natural_spawn,
                                                             spawn_rules, world_spawn, frame_limiter, game_loop)

Nothing needs Ludovic.

🤖 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/353 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/proto-save-off-main` --- ### 📝 Commits (1) - [`1b46810`](https://github.com/horizon-rust/horizon/commit/1b468100aa173691a246d5d18344873096a5e223) Save proto chunks on a worker, not the main thread (#224) ### 📊 Changes **2 files changed** (+75 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/streaming.rs` (+69 -16) 📝 `crates/horizon-client/tests/generation_saves.rs` (+6 -0) </details> ### 📄 Description Fixes #224 (the last hitch, left open by #300) ## What Proto chunks that decoration wrote to are now saved by a worker thread, not the main thread: both at the autosave and, while exploring, as they unload behind the player. ## Why #300 noted the remaining hitch: `Streaming::save` converted every written proto chunk on the main thread during the autosave (`VanillaTerrain::saved_proto` → `column()`, a block-by-block copy of the whole proto into a column, then the NBT encoding). The same conversion also ran on the main thread in `Streaming::update`, for every written proto unloaded behind the player, so it hit frames all through exploration, not only at the autosave. Vanilla's autosave hands its chunks to the `IOWorker` too. ## How The protos are checked out of `Streaming::protos` (set to `None`), as a decoration job already does, and sent as a `Job::Save` that runs ahead of every other job (so a column generated again meanwhile finds them saved). The worker calls `ChunkGenerator::save_protos` and hands them back (`Done::Saved`). While a proto is checked out, nothing can decorate or finish it, and generation doesn't ask for it again. A returned proto now out of range is dropped by the next `update` (it is no longer marked written). - Autosave (`save(wait: false)`): check out the written protos and return. - Explicit save, `save-all`, quitting, dimension change (`save(wait: true)`): wait for the decorations, finishing columns **and saves** in flight, then save in place, before the world's chunks, as before. - Dropping the streamer waits for the saves in flight (they hold protos nothing else would save). ## Measurements Mac mini M4 Pro, RD16, PerfBench world (seed 1234), offscreen. As in #300: open the world, then 30 s before the 5-minute autosave (tick 6000), teleport to new terrain (x 20000) and fly +x at 20 blocks/s for 60 s (`horizon-ctl fly … raw`), so decoration writes protos all along and the autosave finds many of them. Main-thread time, measured with temporary timers around `Streaming::save` in the autosave and around `Streaming::update` (not in this PR), two games per build: | | main | this PR | |---|---|---| | `Streaming::save` in the autosave | 178 ms, 371 ms | **0.01 ms, 0.01 ms** | | slowest `Streaming::update` during the 60 s flight | 263 ms, 738 ms | **55 ms, 67 ms** | | explicit save at quit (waits, as before) | 173 ms, 310 ms | 132 ms, 155 ms | Frame times over the flight, five games per build (the two above and three without timers), means with 95% CIs (Student's t): | | main | this PR | |---|---|---| | worst frame within 2 s of the autosave | 292 ± 197 ms | **113 ± 62 ms** | | worst frame elsewhere in the flight | 241 ± 108 ms | 172 ± 66 ms | | p99 frame | 115 ± 108 ms | 57 ± 34 ms | Other sessions were compiling on the Mac mini throughout (load average up to ~80), which is why the frame times are wide; the main-thread timers above are the clean signal. The 55–67 ms left in `Streaming::update` is other streaming work, not saving (a follow-up). ## How tested ``` cargo fmt --all -- --check OK cargo clippy --workspace --all-targets -- -D warnings OK cargo test -p horizon-client all passed generation_saves::chunks_left_behind_keep_their_decoration now autosaves (no wait) after each step of the walk and after the far teleport, then comes back: every column is still finished exactly once with all its neighbours' decoration parity.py --changed origin/main 80 passed, 0 failed (one run on the merge of this PR with its three siblings: #270 relight remesh, #224 proto saves, #271 frame cap, spawn heightmap; includes section_mesh, light, natural_spawn, spawn_rules, world_spawn, frame_limiter, game_loop) ``` Nothing needs Ludovic. 🤖 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 15:56:49 +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#2513
No description provided.