[PR #4279] [MERGED] Share one loot table map between Items and the loot data of the same root and packs #5537

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

📋 Pull Request Information

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

Base: main ← Head: perf/shared-loot-tables


📝 Commits (6)

  • d3be73f Share one loot table map between Items and the loot data of the same root and packs
  • 50fd824 Merge remote-tracking branch 'origin/main' into perf/shared-loot-tables
  • f8f1679 Merge remote-tracking branch 'origin/main' into HEAD
  • fc4641b Shared loot tables: a table changed on disk is read again
  • 7192a53 Merge remote-tracking branch 'origin/main' into HEAD
  • b546ffb Merge remote-tracking branch 'origin/main' into HEAD

📊 Changes

2 files changed (+121 additions, -51 deletions)

View changed files

📝 crates/horizon-items/src/items.rs (+7 -47)
📝 crates/horizon-world/src/loot.rs (+114 -4)

📄 Description

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

Server-next W4, item 6 of the ranked list on plan #3989. Items::load (walk_loot) and LootData::load (load_kind) each parsed every loot table into its own HashMap<String, Value>: about 7 MB per copy. A dedicated server held three copies: Items, worldgen's LootData, and the world's LootData (#4245 removes that last one separately).

  • horizon_world::loot::shared_tables(root, overlay) loads the tables of every namespace in data/, with the packs' tables over them. It returns an Arc that is shared while held: a cache of Weaks keyed by the root and the packs' loot_table files. LootData.tables and Items.loot are now Arc<HashMap<String, Value>> from it, so one root plus one set of packs means one map.
  • Items now reads the loot tables of every namespace in data/, as LootData always did. Before, it read minecraft plus the content mods' listed namespaces. A vanilla root has only minecraft, and a content root's data namespaces are its mods'.
  • One behaviour to know: while a copy is held, a root's table files are not read again. Pack changes still reload, because their bytes are in the key. Resource roots don't change under a running game. loads_every_namespace rewrote a file in place while holding the first copy, so it now drops it first.
  • New test loot_tables_are_shared_per_root_and_packs.

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 bb6406719:

Build Round 1 Round 2 Round 3
main bb6406719 341 MB 337 MB 340 MB
this PR 325 MB 326 MB 327 MB

−14 MB idle: two of the three copies. With #4245 as well, the world's second LootData also stops duplicating its modifiers, predicates and enchantments (~1 MB more). Ready time unchanged.

Re-measured after #4245 merged (main 45982faa5 against this PR merged with it, 50fd82435; same playhorizon setup, 3 interleaved rounds):

round 1 round 2 round 3
main 45982faa5 328 MB 331 MB 333 MB
this PR 326 MB 324 MB 322 MB

−7 MB on top of #4245 (one loot-table copy left instead of two).

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

Check Result
Scope ✅ 2 files, +73 −51
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 46 s)
rustfmt ✅ (5 s)
clippy ✅ (31 s)
tests: horizon-items, horizon-world ✅ 315 passed (1 min 23 s)
doc tests ✅ 0 passed (2 s)
content root tests ✅ 5 passed (1 min 43 s)
Parity ➖ 112 affected, run in CI (run-parity): entity_death_loot, dedicated_server…

🤖 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/4279 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/shared-loot-tables` --- ### 📝 Commits (6) - [`d3be73f`](https://github.com/horizon-rust/horizon/commit/d3be73f9d056262003c4bb74a7bc6ab96ed040ea) Share one loot table map between Items and the loot data of the same root and packs - [`50fd824`](https://github.com/horizon-rust/horizon/commit/50fd82435c133b2ff18fba41a73b3a88a9aa1dbf) Merge remote-tracking branch 'origin/main' into perf/shared-loot-tables - [`f8f1679`](https://github.com/horizon-rust/horizon/commit/f8f1679153e35533155b7e946ecfd1fa8e55b703) Merge remote-tracking branch 'origin/main' into HEAD - [`fc4641b`](https://github.com/horizon-rust/horizon/commit/fc4641bc8e33ab43c4000c3ee472b17edecc13de) Shared loot tables: a table changed on disk is read again - [`7192a53`](https://github.com/horizon-rust/horizon/commit/7192a53328c71ef2ac24571af7e52e3713074c51) Merge remote-tracking branch 'origin/main' into HEAD - [`b546ffb`](https://github.com/horizon-rust/horizon/commit/b546ffb8773dd3cb4db277a4c31634f207273bf1) Merge remote-tracking branch 'origin/main' into HEAD ### 📊 Changes **2 files changed** (+121 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-items/src/items.rs` (+7 -47) 📝 `crates/horizon-world/src/loot.rs` (+114 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Server-next W4, item 6 of the ranked list on plan #3989. `Items::load` (`walk_loot`) and `LootData::load` (`load_kind`) each parsed every loot table into its own `HashMap<String, Value>`: about 7 MB per copy. A dedicated server held three copies: `Items`, worldgen's `LootData`, and the world's `LootData` (#4245 removes that last one separately). - `horizon_world::loot::shared_tables(root, overlay)` loads the tables of every namespace in `data/`, with the packs' tables over them. It returns an `Arc` that is shared while held: a cache of `Weak`s keyed by the root and the packs' `loot_table` files. `LootData.tables` and `Items.loot` are now `Arc<HashMap<String, Value>>` from it, so one root plus one set of packs means one map. - `Items` now reads the loot tables of every namespace in `data/`, as `LootData` always did. Before, it read `minecraft` plus the content mods' listed namespaces. A vanilla root has only `minecraft`, and a content root's data namespaces are its mods'. - One behaviour to know: while a copy is held, a root's table files are not read again. Pack changes still reload, because their bytes are in the key. Resource roots don't change under a running game. `loads_every_namespace` rewrote a file in place while holding the first copy, so it now drops it first. - New test `loot_tables_are_shared_per_root_and_packs`. ## 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 bb6406719: | Build | Round 1 | Round 2 | Round 3 | |---|---|---|---| | main bb6406719 | 341 MB | 337 MB | 340 MB | | this PR | 325 MB | 326 MB | 327 MB | −14 MB idle: two of the three copies. With #4245 as well, the world's second `LootData` also stops duplicating its modifiers, predicates and enchantments (~1 MB more). Ready time unchanged. Re-measured after #4245 merged (main 45982faa5 against this PR merged with it, 50fd82435; same playhorizon setup, 3 interleaved rounds): | | round 1 | round 2 | round 3 | |---|---|---|---| | main 45982faa5 | 328 MB | 331 MB | 333 MB | | this PR | 326 MB | 324 MB | 322 MB | −7 MB on top of #4245 (one loot-table copy left instead of two). **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at bb6406719, 5 min 55 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +73 −51 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 46 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (31 s) | | tests: horizon-items, horizon-world | ✅ 315 passed (1 min 23 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ✅ 5 passed (1 min 43 s) | | Parity | ➖ 112 affected, run in CI (`run-parity`): entity_death_loot, dedicated_server… | 🤖 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:16 +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#5537
No description provided.