[PR #7397] [MERGED] startup: snapshot the block-state registry beside behaviours-v2.bin #7575

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

📋 Pull Request Information

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

Base: main ← Head: t3/block-registry-snapshot-cache


📝 Commits (1)

  • 2a00122 startup: snapshot the block-state registry beside behaviours-v2.bin

📊 Changes

6 files changed (+565 additions, -51 deletions)

View changed files

📝 crates/horizon-client-render/src/assets.rs (+1 -2)
📝 crates/horizon-world/src/level/data.rs (+13 -2)
📝 crates/horizon-world/src/level/data/cache.rs (+281 -44)
📝 crates/horizon-world/src/level/mod.rs (+4 -3)
📝 crates/horizon-world/src/registry.rs (+1 -0)
➕ crates/horizon-world/src/registry/snapshot.rs (+265 -0)

📄 Description

🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally.

Closes #7394.

Summary

  • level/data/cache.rs keeps a second snapshot, registry-v1.bin, beside behaviours-v2.bin: same framing (magic, version, SHA-256 fingerprint of the sources + the running executable, SHA-256-checked lz4+postcard body in .horizon-cache, safe fallback). facts.json is the registry's only source, so its fingerprint hashes just that file.
  • registry/snapshot.rs serializes the built BlockRegistry compactly: a string table (block names, property names and values — a few hundred distinct strings) + states, ids, collided, defaults and the (air, fluid) flags as indexes into it. No Value trees. Restore re-interns through SharedStrings, so the process still holds one copy of each string.
  • data::load_registry tries the snapshot first; the new load_registry_with_flags serves flag users, and Assets::load takes it — the client's startup registry parse is the cached path.
  • The fingerprint's content digest now hashes a file in 4 MB pieces across the idle cores — a scheme of the bytes alone (the same digest on every machine) — which also speeds the behaviours fingerprint over the ~70 MB source set.

Measured with behaviour_load_profile (fast build, M1 Pro, 35,723 states):

load before snapshot hit
registry ~60 ms ~24 ms (~2.5×)
behaviours first load (cached) ~575 ms ~115 ms

registry-v1.bin is 628 KB vs the 9.7 MB facts.json. The first run after a resource or executable change pays parse+store once (~90 ms).

Test plan

  • registry::snapshot::tests: roundtrip of the built tables (shared strings checked by pointer); out-of-range ids, strings, defaults and flag bits rejected.
  • level::data::cache::tests::registry_snapshot_roundtrips_and_recovers_from_corruption: real facts.json — identical states/ids/defaults/flags after a hit; invalidation on a modified source, a corrupt body, a foreign key.
  • content_hash_pieces_in_order pins the digest scheme.
  • python3 tools/pr_ready.py --quick: fmt, clippy -D warnings, 1576 tests pass. (Locally, level::tests::pistons_* fail identically on origin/main when run against prepared resources — pre-existing, unrelated.)

~570 lines: ~190 are tests.

🤖 Generated with Devin


🔄 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/7397 **Author:** [@socksprox](https://github.com/socksprox) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `t3/block-registry-snapshot-cache` --- ### 📝 Commits (1) - [`2a00122`](https://github.com/horizon-rust/horizon/commit/2a001222fc8c514ee6a20c0719c2e8a0d6092dbb) startup: snapshot the block-state registry beside behaviours-v2.bin ### 📊 Changes **6 files changed** (+565 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/assets.rs` (+1 -2) 📝 `crates/horizon-world/src/level/data.rs` (+13 -2) 📝 `crates/horizon-world/src/level/data/cache.rs` (+281 -44) 📝 `crates/horizon-world/src/level/mod.rs` (+4 -3) 📝 `crates/horizon-world/src/registry.rs` (+1 -0) ➕ `crates/horizon-world/src/registry/snapshot.rs` (+265 -0) </details> ### 📄 Description > 🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally. Closes #7394. ## Summary - `level/data/cache.rs` keeps a second snapshot, `registry-v1.bin`, beside `behaviours-v2.bin`: same framing (magic, version, SHA-256 fingerprint of the sources + the running executable, SHA-256-checked lz4+postcard body in `.horizon-cache`, safe fallback). `facts.json` is the registry's only source, so its fingerprint hashes just that file. - `registry/snapshot.rs` serializes the built `BlockRegistry` compactly: a string table (block names, property names and values — a few hundred distinct strings) + states, `ids`, `collided`, `defaults` and the `(air, fluid)` flags as indexes into it. No `Value` trees. Restore re-interns through `SharedStrings`, so the process still holds one copy of each string. - `data::load_registry` tries the snapshot first; the new `load_registry_with_flags` serves flag users, and `Assets::load` takes it — the client's startup registry parse is the cached path. - The fingerprint's content digest now hashes a file in 4 MB pieces across the idle cores — a scheme of the bytes alone (the same digest on every machine) — which also speeds the behaviours fingerprint over the ~70 MB source set. Measured with `behaviour_load_profile` (fast build, M1 Pro, 35,723 states): | load | before | snapshot hit | | --- | --- | --- | | registry | ~60 ms | ~24 ms (~2.5×) | | behaviours first load (cached) | ~575 ms | ~115 ms | `registry-v1.bin` is 628 KB vs the 9.7 MB `facts.json`. The first run after a resource or executable change pays parse+store once (~90 ms). #### Test plan - [x] `registry::snapshot::tests`: roundtrip of the built tables (shared strings checked by pointer); out-of-range ids, strings, defaults and flag bits rejected. - [x] `level::data::cache::tests::registry_snapshot_roundtrips_and_recovers_from_corruption`: real `facts.json` — identical states/ids/defaults/flags after a hit; invalidation on a modified source, a corrupt body, a foreign key. - [x] `content_hash_pieces_in_order` pins the digest scheme. - [x] `python3 tools/pr_ready.py --quick`: fmt, clippy `-D warnings`, 1576 tests pass. (Locally, `level::tests::pistons_*` fail identically on `origin/main` when run against prepared resources — pre-existing, unrelated.) ~570 lines: ~190 are tests. 🤖 Generated with [Devin](https://devin.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:07 +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#7575
No description provided.