[PR #7262] [MERGED] horizon-ctl memory: the live heap by startup step, span and job #7451

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

📋 Pull Request Information

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

Base: main ← Head: perf/alloc-census


📝 Commits (1)

  • a2bbcb4 horizon-ctl memory: the live heap by startup step, span and job

📊 Changes

10 files changed (+338 additions, -8 deletions)

View changed files

📝 crates/horizon-client-render/src/spans.rs (+11 -1)
📝 crates/horizon-client-render/src/streaming.rs (+15 -4)
📝 crates/horizon-client/Cargo.toml (+3 -0)
📝 crates/horizon-client/src/bin/horizon-ctl/commands.rs (+1 -1)
📝 crates/horizon-client/src/game/memory.rs (+9 -0)
📝 crates/horizon-client/src/main.rs (+4 -1)
📝 crates/horizon-threads/Cargo.toml (+4 -0)
➕ crates/horizon-threads/src/heap_census.rs (+269 -0)
📝 crates/horizon-threads/src/jobs.rs (+9 -1)
📝 crates/horizon-threads/src/lib.rs (+13 -0)

📄 Description

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

What

horizon-ctl memory can now say who holds the heap. A build with the new alloc-census feature (cargo build -p horizon-client --features alloc-census) runs mimalloc with a 16-byte tag in front of each block. The tag is what ran on the allocating thread: the innermost startup step (startup::time / startup::step), timed span (spans::time) or pool job (jobs::Source::label, by default the source's type; the streaming jobs say stream.generate, stream.finish, stream.light, stream.mesh…), else the thread's OS name. The report gains heap_by_tag_mb: live bytes per tag, largest first.

Why: heaptrack can't profile the game on playhorizon. Its interpreter grew to 18 GB with line tables and filled the swap, and without DWARF it still went past a 7 GB cap during the load. This tool runs beside the game for 16 bytes per block.

Without the feature nothing changes. HEAP_CENSUS is a const false, so heap_tag is a constant None, startup::step still returns None when tracing is off, and the pool job's tag closure is never called.

What it found (main, playhorizon, headless, server thread, seed 1234)

tag (MB live) title RD 8 RD 32 back to RD 8
stream.generate 0 38 84 69
stream.finish 0 11 95 18
stream.light 0 15 56 17
ui.atlas (headless only: packed with a window, #6843) 82 82 82 82
core.block_models_sprites 50 50 50 50
core.visibility 16 16 16 16
worldgen + world data preloads 28 28 28 28
sum of tags 265 397 663 471
RSS 429 645 999 831
  • At RD 32 the streaming jobs hold 235 MB: the server's columns (147 MB) plus the generation ring's proto chunks.
  • After going from RD 32 back to RD 8, the live heap falls back to 471 MB but RSS stays at ~835 MB for 2 minutes. That is fragmentation in partly used pages. Letting every idle worker mi_collect its own heap changed nothing (845 vs 823 MB), so it is not in this PR.

Checks

  • cargo test -p horizon-threads --lib heap_census: 2 tests. A block counts for its step until another thread frees it, and grows under the same tag. Without a step, a block counts for its thread's name.
  • cargo clippy -p horizon-threads --features alloc-census --lib --tests -D warnings and cargo clippy -p horizon-client --features alloc-census --bin horizon-client -D warnings: clean.
  • The census build ran the RD 8 / 16 / 32 / 8 ramps above. The default build is unchanged.

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 8a45d7f9f, 40 min 25 s)

Check Result
Scope ✅ 10 files, +338 −8
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 612 run, FAILED (failures=2, skipped=1) (1 min 5 s)
rustfmt ✅ (13 s)
clippy ✅ (6 min 20 s)
tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-threads ✅ 3276 passed (31 min 38 s)
doc tests ✅ 0 passed (6 s)
content root tests ➖ content root untouched
mod API up to date ✅ (46 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 148 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 136 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The two Python failures are test_lab's test_macos_and_windows_start_no_virtual_screen: the playhorizon runner's own VSCREEN leaks into the test (same on main).

Label: skip-release (a measuring build; players get nothing new).

🤖 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/7262 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/alloc-census` --- ### 📝 Commits (1) - [`a2bbcb4`](https://github.com/horizon-rust/horizon/commit/a2bbcb4fed2bde9862baa8866b1fa571b0943ca6) horizon-ctl memory: the live heap by startup step, span and job ### 📊 Changes **10 files changed** (+338 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/spans.rs` (+11 -1) 📝 `crates/horizon-client-render/src/streaming.rs` (+15 -4) 📝 `crates/horizon-client/Cargo.toml` (+3 -0) 📝 `crates/horizon-client/src/bin/horizon-ctl/commands.rs` (+1 -1) 📝 `crates/horizon-client/src/game/memory.rs` (+9 -0) 📝 `crates/horizon-client/src/main.rs` (+4 -1) 📝 `crates/horizon-threads/Cargo.toml` (+4 -0) ➕ `crates/horizon-threads/src/heap_census.rs` (+269 -0) 📝 `crates/horizon-threads/src/jobs.rs` (+9 -1) 📝 `crates/horizon-threads/src/lib.rs` (+13 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What `horizon-ctl memory` can now say who holds the heap. A build with the new `alloc-census` feature (`cargo build -p horizon-client --features alloc-census`) runs mimalloc with a 16-byte tag in front of each block. The tag is what ran on the allocating thread: the innermost startup step (`startup::time` / `startup::step`), timed span (`spans::time`) or pool job (`jobs::Source::label`, by default the source's type; the streaming jobs say `stream.generate`, `stream.finish`, `stream.light`, `stream.mesh`…), else the thread's OS name. The report gains `heap_by_tag_mb`: live bytes per tag, largest first. Why: heaptrack can't profile the game on playhorizon. Its interpreter grew to 18 GB with line tables and filled the swap, and without DWARF it still went past a 7 GB cap during the load. This tool runs beside the game for 16 bytes per block. Without the feature nothing changes. `HEAP_CENSUS` is a `const false`, so `heap_tag` is a constant `None`, `startup::step` still returns `None` when tracing is off, and the pool job's tag closure is never called. ## What it found (main, playhorizon, headless, server thread, seed 1234) | tag (MB live) | title | RD 8 | RD 32 | back to RD 8 | |---|---|---|---|---| | stream.generate | 0 | 38 | 84 | 69 | | stream.finish | 0 | 11 | 95 | 18 | | stream.light | 0 | 15 | 56 | 17 | | ui.atlas (headless only: packed with a window, #6843) | 82 | 82 | 82 | 82 | | core.block_models_sprites | 50 | 50 | 50 | 50 | | core.visibility | 16 | 16 | 16 | 16 | | worldgen + world data preloads | 28 | 28 | 28 | 28 | | sum of tags | 265 | 397 | 663 | 471 | | RSS | 429 | 645 | 999 | 831 | - At RD 32 the streaming jobs hold 235 MB: the server's columns (147 MB) plus the generation ring's proto chunks. - After going from RD 32 back to RD 8, the live heap falls back to 471 MB but RSS stays at ~835 MB for 2 minutes. That is fragmentation in partly used pages. Letting every idle worker `mi_collect` its own heap changed nothing (845 vs 823 MB), so it is not in this PR. ## Checks - `cargo test -p horizon-threads --lib heap_census`: 2 tests. A block counts for its step until another thread frees it, and grows under the same tag. Without a step, a block counts for its thread's name. - `cargo clippy -p horizon-threads --features alloc-census --lib --tests -D warnings` and `cargo clippy -p horizon-client --features alloc-census --bin horizon-client -D warnings`: clean. - The census build ran the RD 8 / 16 / 32 / 8 ramps above. The default build is unchanged. **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 8a45d7f9f, 40 min 25 s) | Check | Result | | --- | --- | | Scope | ✅ 10 files, +338 −8 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 612 run, FAILED (failures=2, skipped=1) (1 min 5 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (6 min 20 s) | | tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-threads | ✅ 3276 passed (31 min 38 s) | | doc tests | ✅ 0 passed (6 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (46 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 148 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 136 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The two Python failures are `test_lab`'s `test_macos_and_windows_start_no_virtual_screen`: the playhorizon runner's own `VSCREEN` leaks into the test (same on main). Label: `skip-release` (a measuring build; players get nothing new). 🤖 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:39:43 +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#7451
No description provided.