[PR #753] [MERGED] Block tables: check states while reading, without the 240 MB tree #2780

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

📋 Pull Request Information

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

Base: main ← Head: perf/nbt-table-memory


📝 Commits (1)

  • 2e531f3 Per-state tables: check state identities while reading, never as a tree

📊 Changes

14 files changed (+421 additions, -124 deletions)

View changed files

📝 crates/horizon-client/examples/resource_memory.rs (+0 -14)
📝 crates/horizon-client/src/collisions.rs (+4 -10)
📝 crates/horizon-client/src/light.rs (+3 -11)
📝 crates/horizon-client/src/models.rs (+3 -5)
📝 crates/horizon-client/src/motion.rs (+3 -9)
📝 crates/horizon-world/src/block_properties.rs (+18 -17)
📝 crates/horizon-world/src/block_support.rs (+12 -4)
📝 crates/horizon-world/src/collision.rs (+6 -13)
📝 crates/horizon-world/src/level/data.rs (+3 -10)
📝 crates/horizon-world/src/movement_properties.rs (+5 -13)
📝 crates/horizon-world/src/nbt.rs (+164 -3)
📝 crates/horizon-world/src/registry.rs (+117 -0)
📝 crates/horizon-world/src/worldgen/generator_blocks.rs (+11 -15)
📝 crates/horizon-world/tests/collision_data.rs (+72 -0)

📄 Description

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

Part of the modpack memory work (docs/modpacks.md, "Where the RAM goes").

What

occlusion.nbt, cached-collision.nbt, cached-support.nbt, block-properties.nbt (which nests a second occlusion table) and movement-properties.nbt each start with states, the identity of every block state in id order, and every loader parsed the whole file into an NBT tree before checking it. NBT compounds are BTreeMaps, so each state costs two B-tree nodes: about 240 MB of tree per table for ATM10's carried mods (153,511 states), allocated and freed six times while the game starts.

  • nbt::read_named_streaming reads like read_named, but lists with a given key in the root compound or in a compound directly under it go to a visitor element by element. The tree keeps them empty.
  • registry::BlockTableFile reads a table that way and checks each state against the registry as it arrives (count, then identity in id order).
  • registry::BlockTable is a table whose states have been checked, either while reading or as a tree (BlockTable::check). The collision, support, block-property and movement loaders gain from_table. from_nbt stays for trees built in memory (tests, fixtures) and checks exactly as before.
  • The game's readers (light, face visibility, collisions, motion, level data, worldgen block behaviour) use BlockTableFile.

A table whose states differ, whose count differs, or which has no states is refused as before. A nested table is accepted without a second check only one level below a table read this way (block-properties.nbt's occlusion). Anything deeper is checked as a tree, so an emptied list there is refused.

Numbers

examples/resource_memory.rs (live heap with a counting allocator), ATM10's 42 carried data-tier mods, 153,511 states, Mac mini M4 Pro. Each row is the step's heap peak:

step before MB after MB
light tables (occlusion.nbt) 911 699
collision (cached-collision.nbt) 945 733
motion (movement-properties.nbt) 1,427 1,215
worldgen (three tables, uncached) 3,000 2,788

The live heap after loading is unchanged (887 MB). The per-step peak falls by about 210 MB at each table. The remaining peaks are JSON trees (facts.json, gameplay-facts.json); the follow-up PRs handle the largest.

In game (tools/perf_bench.py --port-work, RD 8, a first start, one game each, machine load average 80-125): footprint peak 2,625 → 2,534 MB. Steady footprint 2,369 → 2,402 MB and RSS 4,346 → 4,320 MB are within the noise. The allocator reuses the freed tree pages for later allocations, so this cuts peaks and allocation work, not what stays resident.

Vanilla is unaffected in behaviour: the same files, the same checks, the same shapes.

Checks

  • cargo fmt --all -- --check, cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings: clean.
  • cargo test -p horizon-world: all pass, including:
    • nbt::tests::streamed_lists_reach_the_visitor_and_stay_empty_in_the_tree
    • collision_data::streamed_tables_check_states_while_reading: the streamed and tree loads give the same shapes; swapped, short and missing states are refused; a nested table works.
  • cargo test -p horizon-client: all pass.
  • Parity: tools/parity.py --changed origin/main on this work merged together (#753, #754, #755, #756, #764 and #762): 298 harnesses selected, all pass. Three failed on the first run for reasons outside this code, and their reruns passed: datafix lost its connection while generating 1.8.9 sample worlds (load average 140), the Java oracle timed out in decoration, and another session's pkill killed a run.

🤖 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/753 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/nbt-table-memory` --- ### 📝 Commits (1) - [`2e531f3`](https://github.com/horizon-rust/horizon/commit/2e531f35e52638330e838036d5b74de600a65216) Per-state tables: check state identities while reading, never as a tree ### 📊 Changes **14 files changed** (+421 additions, -124 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/resource_memory.rs` (+0 -14) 📝 `crates/horizon-client/src/collisions.rs` (+4 -10) 📝 `crates/horizon-client/src/light.rs` (+3 -11) 📝 `crates/horizon-client/src/models.rs` (+3 -5) 📝 `crates/horizon-client/src/motion.rs` (+3 -9) 📝 `crates/horizon-world/src/block_properties.rs` (+18 -17) 📝 `crates/horizon-world/src/block_support.rs` (+12 -4) 📝 `crates/horizon-world/src/collision.rs` (+6 -13) 📝 `crates/horizon-world/src/level/data.rs` (+3 -10) 📝 `crates/horizon-world/src/movement_properties.rs` (+5 -13) 📝 `crates/horizon-world/src/nbt.rs` (+164 -3) 📝 `crates/horizon-world/src/registry.rs` (+117 -0) 📝 `crates/horizon-world/src/worldgen/generator_blocks.rs` (+11 -15) 📝 `crates/horizon-world/tests/collision_data.rs` (+72 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the modpack memory work (docs/modpacks.md, "Where the RAM goes"). ## What `occlusion.nbt`, `cached-collision.nbt`, `cached-support.nbt`, `block-properties.nbt` (which nests a second occlusion table) and `movement-properties.nbt` each start with `states`, the identity of every block state in id order, and every loader parsed the whole file into an NBT tree before checking it. NBT compounds are `BTreeMap`s, so each state costs two B-tree nodes: **about 240 MB of tree per table** for ATM10's carried mods (153,511 states), allocated and freed six times while the game starts. - `nbt::read_named_streaming` reads like `read_named`, but lists with a given key in the root compound or in a compound directly under it go to a visitor element by element. The tree keeps them empty. - `registry::BlockTableFile` reads a table that way and checks each state against the registry as it arrives (count, then identity in id order). - `registry::BlockTable` is a table whose states have been checked, either while reading or as a tree (`BlockTable::check`). The collision, support, block-property and movement loaders gain `from_table`. `from_nbt` stays for trees built in memory (tests, fixtures) and checks exactly as before. - The game's readers (light, face visibility, collisions, motion, level data, worldgen block behaviour) use `BlockTableFile`. A table whose states differ, whose count differs, or which has no `states` is refused as before. A nested table is accepted without a second check only one level below a table read this way (`block-properties.nbt`'s `occlusion`). Anything deeper is checked as a tree, so an emptied list there is refused. ## Numbers `examples/resource_memory.rs` (live heap with a counting allocator), ATM10's 42 carried data-tier mods, 153,511 states, Mac mini M4 Pro. Each row is the step's heap peak: | step | before MB | after MB | |---|---:|---:| | light tables (`occlusion.nbt`) | 911 | 699 | | collision (`cached-collision.nbt`) | 945 | 733 | | motion (`movement-properties.nbt`) | 1,427 | 1,215 | | worldgen (three tables, uncached) | 3,000 | 2,788 | The live heap after loading is unchanged (887 MB). The per-step peak falls by about 210 MB at each table. The remaining peaks are JSON trees (`facts.json`, `gameplay-facts.json`); the follow-up PRs handle the largest. In game (`tools/perf_bench.py --port-work`, RD 8, a first start, one game each, machine load average 80-125): footprint peak 2,625 → 2,534 MB. Steady footprint 2,369 → 2,402 MB and RSS 4,346 → 4,320 MB are within the noise. The allocator reuses the freed tree pages for later allocations, so this cuts peaks and allocation work, not what stays resident. Vanilla is unaffected in behaviour: the same files, the same checks, the same shapes. ## Checks - `cargo fmt --all -- --check`, `cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings`: clean. - `cargo test -p horizon-world`: all pass, including: - `nbt::tests::streamed_lists_reach_the_visitor_and_stay_empty_in_the_tree` - `collision_data::streamed_tables_check_states_while_reading`: the streamed and tree loads give the same shapes; swapped, short and missing `states` are refused; a nested table works. - `cargo test -p horizon-client`: all pass. - Parity: `tools/parity.py --changed origin/main` on this work merged together (#753, #754, #755, #756, #764 and #762): 298 harnesses selected, **all pass**. Three failed on the first run for reasons outside this code, and their reruns passed: datafix lost its connection while generating 1.8.9 sample worlds (load average 140), the Java oracle timed out in decoration, and another session's `pkill` killed a run. 🤖 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:58:59 +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#2780
No description provided.