[PR #825] [MERGED] Block registry: read facts.json as it streams #2838

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

📋 Pull Request Information

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

Base: main ← Head: perf/facts-registry-stream


📝 Commits (1)

  • 9190d14 Block registry: read facts.json as it streams

📊 Changes

4 files changed (+228 additions, -107 deletions)

View changed files

📝 crates/horizon-client/src/assets.rs (+16 -57)
📝 crates/horizon-world/src/level/data.rs (+2 -38)
📝 crates/horizon-world/src/registry.rs (+46 -12)
➕ crates/horizon-world/src/registry/facts.rs (+164 -0)

📄 Description

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

What

facts.json went through two trees at every start, in both the world's load_registry and the client's Assets::load: a serde_json::Value of the whole file, then an NBT Tag tree of every state, then BlockRegistry::from_nbt. docs/modpacks.md lists it as one of the startup peaks left with content mods.

BlockRegistry::from_facts_json now deserializes only what the registry needs as the file streams: each row's state (column 4: a name or {id, properties}, as BlockState::from_nbt reads it), and defaults. from_facts_json_with_flags also returns each row's air and fluid columns, which Assets::load used the JSON tree for. from_nbt and the new path share one from_states core, so the checks (duplicate states, defaults naming their block, every block with a default) are the same. Assets resolves tag members against the registry's defaults instead of the JSON's.

Measured (examples/resource_memory, release, Mac mini)

root step heap peak before MB after MB RSS after the step, before / after MB
vanilla (35,723 states) registry 138 27 163 / 44
vanilla assets 179 119 311 / 172
214,338 states (vanilla's ×6, ATM10's size) registry 816 153 924 / 208
same assets 816 235 1,344 / 442

The live registry is unchanged (24 MB vanilla, 139 MB at 214k states); only the parse garbage goes. The 214k root is a synthetic facts.json (vanilla's states renamed five times), so later steps of that run fail and only these two rows are shown.

Self-check

  • cargo fmt --all --check, cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings: clean (rebased on main after #823)
  • cargo test -p horizon-world --lib registry::facts: 2 passed. matches_the_tree_built_registry builds the prepared facts.json both ways and compares every state, default and air/fluid flag; reads_states_and_defaults covers both state shapes, extra columns and three malformed files.
  • tools/parity.py block_properties heightmap light section_mesh registry_fluid worldgen: 6 passed

Nothing needs Ludovic.

🤖 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/825 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/facts-registry-stream` --- ### 📝 Commits (1) - [`9190d14`](https://github.com/horizon-rust/horizon/commit/9190d14b7fa88fb7e409d72b1be48d112f5a35c3) Block registry: read facts.json as it streams ### 📊 Changes **4 files changed** (+228 additions, -107 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/assets.rs` (+16 -57) 📝 `crates/horizon-world/src/level/data.rs` (+2 -38) 📝 `crates/horizon-world/src/registry.rs` (+46 -12) ➕ `crates/horizon-world/src/registry/facts.rs` (+164 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What `facts.json` went through two trees at every start, in both the world's `load_registry` and the client's `Assets::load`: a `serde_json::Value` of the whole file, then an NBT `Tag` tree of every state, then `BlockRegistry::from_nbt`. docs/modpacks.md lists it as one of the startup peaks left with content mods. `BlockRegistry::from_facts_json` now deserializes only what the registry needs as the file streams: each row's state (column 4: a name or `{id, properties}`, as `BlockState::from_nbt` reads it), and `defaults`. `from_facts_json_with_flags` also returns each row's air and fluid columns, which `Assets::load` used the JSON tree for. `from_nbt` and the new path share one `from_states` core, so the checks (duplicate states, defaults naming their block, every block with a default) are the same. `Assets` resolves tag members against the registry's defaults instead of the JSON's. ## Measured (`examples/resource_memory`, release, Mac mini) | root | step | heap peak before MB | after MB | RSS after the step, before / after MB | |---|---|---:|---:|---:| | vanilla (35,723 states) | registry | 138 | 27 | 163 / 44 | | vanilla | assets | 179 | 119 | 311 / 172 | | 214,338 states (vanilla's ×6, ATM10's size) | registry | 816 | 153 | 924 / 208 | | same | assets | 816 | 235 | 1,344 / 442 | The live registry is unchanged (24 MB vanilla, 139 MB at 214k states); only the parse garbage goes. The 214k root is a synthetic `facts.json` (vanilla's states renamed five times), so later steps of that run fail and only these two rows are shown. ## Self-check - `cargo fmt --all --check`, `cargo clippy -p horizon-world -p horizon-client --all-targets -- -D warnings`: clean (rebased on main after #823) - `cargo test -p horizon-world --lib registry::facts`: 2 passed. `matches_the_tree_built_registry` builds the prepared `facts.json` both ways and compares every state, default and air/fluid flag; `reads_states_and_defaults` covers both state shapes, extra columns and three malformed files. - `tools/parity.py block_properties heightmap light section_mesh registry_fluid worldgen`: 6 passed Nothing needs Ludovic. 🤖 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:59:28 +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#2838
No description provided.