[PR #4245] [MERGED] Load the loot data once when a world opens with the packs world generation used #5513

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

📋 Pull Request Information

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

Base: main ← Head: perf/one-loot-data


📝 Commits (1)

  • 2c526aa Load the loot data once when a world opens with the packs world generation used

📊 Changes

2 files changed (+78 additions, -13 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -2)
📝 crates/horizon-client/src/structure_blocks.rs (+77 -11)

📄 Description

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

Server-next W4 (idle memory, plan #3989). The heap profile of an idle dedicated server held two LootData, 7.9 MB each. World generation loads it with no packs while the world is prepared (VanillaTerrain, structure_blocks::loot_data), and keeps that Arc. Opening the world then called forget_loot_data() and loaded it again with the world's packs. For a world without data packs, the second copy was identical to the first, and both stayed alive for the whole run.

  • structure_blocks::world_loot_data(root, overlay), for world open only, keeps the copy already loaded when it came from the same root and the same pack files (loot_key: a hash of the root and the overlay's files). Otherwise it loads a fresh one, as before. A world with data packs, or another root, still reloads; /reload still forgets.
  • loot_data keeps its contract: it returns the cached copy whatever overlay the caller passes, so worldgen's PackOverlay::NONE call cannot make the cache flip.
  • New unit test a_world_open_reuses_loot_data_of_the_same_packs: same packs, same Arc; other packs, fresh load. It uses a local slot, not the process-wide cache.

Idle memory A/B

Dedicated server, --profile fast --no-default-features, on playhorizon (--cpus 0-3 --exclusive). RSS 10 s after the first status ping (sn_idle.py), 3 interleaved rounds against the parent d129fb7cf:

Build Round 1 Round 2 Round 3 Ready
main d129fb7cf 340 MB 342 MB 340 MB 3.74–3.86 s
this PR 330 MB 332 MB 331 MB 3.72–3.85 s

−10 MB idle. The integrated server's world open takes the same path.

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at d129fb7cf, 5 min 46 s)

Check Result
Scope ✅ 2 files, +78 −13
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 10 s)
rustfmt ✅ (9 s)
clippy ✅ (1 min 20 s)
tests: horizon-client ✅ 971 passed (2 min 47 s)
doc tests ✅ 0 passed (1 s)
Parity ➖ 53 affected, run in CI (run-parity): entity_death_loot, dedicated_server, dispenser…

🤖 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/4245 **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/one-loot-data` --- ### 📝 Commits (1) - [`2c526aa`](https://github.com/horizon-rust/horizon/commit/2c526aa767e458327df693774a8f0ffcdc6532b9) Load the loot data once when a world opens with the packs world generation used ### 📊 Changes **2 files changed** (+78 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -2) 📝 `crates/horizon-client/src/structure_blocks.rs` (+77 -11) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Server-next W4 (idle memory, plan #3989). The heap profile of an idle dedicated server held two `LootData`, 7.9 MB each. World generation loads it with no packs while the world is prepared (`VanillaTerrain`, `structure_blocks::loot_data`), and keeps that `Arc`. Opening the world then called `forget_loot_data()` and loaded it again with the world's packs. For a world without data packs, the second copy was identical to the first, and both stayed alive for the whole run. - `structure_blocks::world_loot_data(root, overlay)`, for world open only, keeps the copy already loaded when it came from the same root and the same pack files (`loot_key`: a hash of the root and the overlay's files). Otherwise it loads a fresh one, as before. A world with data packs, or another root, still reloads; `/reload` still forgets. - `loot_data` keeps its contract: it returns the cached copy whatever overlay the caller passes, so worldgen's `PackOverlay::NONE` call cannot make the cache flip. - New unit test `a_world_open_reuses_loot_data_of_the_same_packs`: same packs, same `Arc`; other packs, fresh load. It uses a local slot, not the process-wide cache. ## Idle memory A/B Dedicated server, `--profile fast --no-default-features`, on playhorizon (`--cpus 0-3 --exclusive`). RSS 10 s after the first status ping (`sn_idle.py`), 3 interleaved rounds against the parent d129fb7cf: | Build | Round 1 | Round 2 | Round 3 | Ready | |---|---|---|---|---| | main d129fb7cf | 340 MB | 342 MB | 340 MB | 3.74–3.86 s | | this PR | 330 MB | 332 MB | 331 MB | 3.72–3.85 s | −10 MB idle. The integrated server's world open takes the same path. **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at d129fb7cf, 5 min 46 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +78 −13 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 10 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (1 min 20 s) | | tests: horizon-client | ✅ 971 passed (2 min 47 s) | | doc tests | ✅ 0 passed (1 s) | | Parity | ➖ 53 affected, run in CI (`run-parity`): entity_death_loot, dedicated_server, dispenser… | 🤖 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:13:06 +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#5513
No description provided.