[PR #4142] [MERGED] Chunk workers: free the generator's scratch buffers after 5 s with nothing to do #5442

Closed
opened 2026-11-03 05:12:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/idle-generator-scratch


📝 Commits (2)

  • e497995 Chunk workers: free the generator's scratch buffers after 5 s with nothing to do
  • f257391 Chunk workers: give freed memory back once every worker is idle

📊 Changes

4 files changed (+64 additions, -2 deletions)

View changed files

📝 crates/horizon-client-render/src/streaming.rs (+42 -2)
📝 crates/horizon-client/src/save.rs (+3 -0)
📝 crates/horizon-client/src/vanillagen.rs (+3 -0)
📝 crates/horizon-world/src/worldgen/generator.rs (+16 -0)

📄 Description

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

What and why

Sixth PR of the server plan (#3989, docs/server-next.md §7, "give memory back"). Independent of the others.

Each streaming worker keeps its generator's density scratch buffers (SamplerContext's scratch, about 384 KB
each, many per worker) and its lookup caches between jobs, for as long as the world is open. On a dedicated server
with nobody on, that was 51 MB of live heap after the spawn area was generated.

Now a worker that has waited IDLE_RELEASE (5 s) with an empty queue does three things:

  • calls ChunkGenerator::idle, which for vanilla terrain frees the three contexts' scratch and the carver-biome,
    structure-biome and height caches (GeneratorWorker::release);
  • drops its mesher face cache;
  • if it is the last worker to go idle, calls horizon_threads::release_free_memory() (malloc_trim /
    malloc_zone_pressure_relief) once.

The next job makes everything again. These are caches and temporaries only, so results don't change. A worker
that has released waits without a timeout until a job wakes it.

Measured

Idle RSS on playhorizon (Linux, server build --profile fast --no-default-features, CPUs 0-3 --exclusive through
tools/remote.sh). sn_idle.py: fresh scratch server, seed 12345, nobody on, RSS 15 s after the first status
ping, 3 interleaved rounds. This change is the top step of the cumulative ladder on main 6d5915897 (#3989):

runs median
main + #4009 #4027 #4078 #4092 #4117 486 / 478 / 478 MB 478 MB
+ this PR 408 / 407 / 406 MB 407 MB (−71)

Ready time doesn't change (4.16 → 4.04 s): the release happens after the spawn area is done.

On macOS the live heap drops by the same 49 MB, but RSS doesn't: the allocator keeps the freed pages, even after
pressure relief. The physical footprint went down 24 MB on the Mac mini.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 1f3ccb0fc, 9 min 40 s)

Check Result
Scope ✅ 4 files, +64 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (2 min 5 s)
rustfmt ✅ (14 s)
clippy ✅ (3 min 3 s)
tests: horizon-client, horizon-client-render, horizon-world ✅ 1801 passed (3 min 49 s)
doc tests ✅ 0 passed (4 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 ➖ 122 affected, to run in CI (--quick): ambient_sound, arrow, attribute_updates, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 110 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Parity: run-parity label for CI.

🤖 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/4142 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/idle-generator-scratch` --- ### 📝 Commits (2) - [`e497995`](https://github.com/horizon-rust/horizon/commit/e497995b44a560359b0857aeed41994793ad6dc0) Chunk workers: free the generator's scratch buffers after 5 s with nothing to do - [`f257391`](https://github.com/horizon-rust/horizon/commit/f257391453d9780471fcc43552a6ecd38cb26af8) Chunk workers: give freed memory back once every worker is idle ### 📊 Changes **4 files changed** (+64 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/streaming.rs` (+42 -2) 📝 `crates/horizon-client/src/save.rs` (+3 -0) 📝 `crates/horizon-client/src/vanillagen.rs` (+3 -0) 📝 `crates/horizon-world/src/worldgen/generator.rs` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Sixth PR of the server plan (#3989, `docs/server-next.md` §7, "give memory back"). Independent of the others. Each streaming worker keeps its generator's density scratch buffers (`SamplerContext`'s `scratch`, about 384 KB each, many per worker) and its lookup caches between jobs, for as long as the world is open. On a dedicated server with nobody on, that was 51 MB of live heap after the spawn area was generated. Now a worker that has waited `IDLE_RELEASE` (5 s) with an empty queue does three things: - calls `ChunkGenerator::idle`, which for vanilla terrain frees the three contexts' scratch and the carver-biome, structure-biome and height caches (`GeneratorWorker::release`); - drops its mesher face cache; - if it is the last worker to go idle, calls `horizon_threads::release_free_memory()` (malloc_trim / malloc_zone_pressure_relief) once. The next job makes everything again. These are caches and temporaries only, so results don't change. A worker that has released waits without a timeout until a job wakes it. ## Measured Idle RSS on playhorizon (Linux, server build `--profile fast --no-default-features`, CPUs 0-3 `--exclusive` through `tools/remote.sh`). `sn_idle.py`: fresh scratch server, seed 12345, nobody on, RSS 15 s after the first status ping, 3 interleaved rounds. This change is the top step of the cumulative ladder on main 6d5915897 (#3989): | | runs | median | |---|---|---| | main + #4009 #4027 #4078 #4092 #4117 | 486 / 478 / 478 MB | 478 MB | | + this PR | 408 / 407 / 406 MB | **407 MB (−71)** | Ready time doesn't change (4.16 → 4.04 s): the release happens after the spawn area is done. On macOS the live heap drops by the same 49 MB, but RSS doesn't: the allocator keeps the freed pages, even after pressure relief. The physical footprint went down 24 MB on the Mac mini. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 1f3ccb0fc, 9 min 40 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +64 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (2 min 5 s) | | rustfmt | ✅ (14 s) | | clippy | ✅ (3 min 3 s) | | tests: horizon-client, horizon-client-render, horizon-world | ✅ 1801 passed (3 min 49 s) | | doc tests | ✅ 0 passed (4 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 | ➖ 122 affected, to run in CI (--quick): ambient_sound, arrow, attribute_updates, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 110 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Parity: `run-parity` label for CI. 🤖 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 05:12:37 +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#5442
No description provided.