[PR #608] [MERGED] Cache resolved block behaviours in versioned binary snapshots #2671

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

📋 Pull Request Information

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

Base: main ← Head: perf/versioned-behaviours-cache


📝 Commits (9)

  • 78791b7 Cache resolved block behaviours across launches
  • 1d3759b Drop a redundant binding flagged by clippy
  • 0789bf0 Keep the behaviours snapshot in the game folder, keyed to the build
  • 2e98f6a Let the behaviour profiler use a snapshot folder
  • 02dce10 Give the behaviour profiler its own name
  • 4a83550 Merge main into perf/versioned-behaviours-cache
  • f0295c1 Merge remote-tracking branch 'pr/607' into HEAD
  • 0a69d6b Merge main and #607 into perf/versioned-behaviours-cache
  • 94209a3 Merge main into perf/versioned-behaviours-cache

📊 Changes

9 files changed (+1025 additions, -7 deletions)

View changed files

📝 .gitignore (+1 -0)
📝 Cargo.lock (+3 -0)
📝 crates/horizon-client/src/game.rs (+3 -0)
📝 crates/horizon-world/Cargo.toml (+3 -0)
➕ crates/horizon-world/examples/behaviour_load_profile.rs (+32 -0)
📝 crates/horizon-world/src/level/data.rs (+52 -7)
➕ crates/horizon-world/src/level/data/cache.rs (+867 -0)
📝 crates/horizon-world/src/level/mod.rs (+7 -0)
➕ tools/profile_behaviour_cache.py (+57 -0)

📄 Description

Behaviours::load previously rebuilt the immutable behaviour tables from several JSON files, collision NBT and tag definitions on each launch. This PR persists the resolved tables in a versioned Postcard/LZ4 binary cache, so subsequent loads can restore the tables directly.

The cache records state facts, collision shape grids and identity metadata, shape flags, resolved block and fluid tags, block metadata, sounds and item bindings. Registry-derived state indexing, dynamic support and runtime-only mutable fields are recreated on restore. Its header includes a format version, SHA-256 fingerprints of all consumed source resources and the caller's registry, and a payload checksum. Bad, old or missing caches fall back to the original loader; writes use a temporary file and atomic rename. Read-only resources still load normally.

Startup loader benchmark

Release-optimized horizon-world loader example with the prepared 26.3 resources. Each set has five independent processes, with three consecutive Behaviours::load calls per process. The baseline and optimized samples use the same prepared resource files (via a separate symlinked root for cache isolation). Numbers below are median elapsed milliseconds; the baseline is original origin/main at f535d1b4 and the final optimized numbers use the Postcard cache on a warmed resource directory.

Behaviour-load call Baseline Warm cache Reduction
First call in process 1,471.0 ms 97.2 ms 93.4%
Second call 1,371.2 ms 92.9 ms 93.2%
Third call 1,157.7 ms 98.2 ms 91.5%

Cold-cache cost: One observed first load, including the initial cache write, was 2,262 ms. This is slower than the baseline first-call median; subsequent launches benefit. The baseline and optimized runs were measured during concurrent development builds, so CPU contention increased variance. These figures measure only behaviour loading; they are not full client time-to-title or time-to-world measurements. The requested tools/profile_client_startup.py did not exist on the starting branch; this PR adds a focused profiler plus a Rust example. It explicitly labels its scope.

Validation

  • Two resource-backed cache tests passed with the final Postcard format: full-field snapshot roundtrip, cache hit, changed-resource invalidation, payload corruption, fallback and rewriting the cache.
  • All 89 horizon-world library tests passed before switching the cache payload from compressed JSON to Postcard; the cache-specific tests were rerun on Postcard and passed.
  • Rust source formatting, Python syntax and git diff --check passed.

Limitations

The cache must fingerprint the consumed resource files on each load, and its first write adds work to an uncached launch. Changes to resource packs or modded registries force rebuilding, but no separate modded-pack benchmark was run. The cache covers behaviour tables; other client startup stages and the registry loader are outside this change.


🔄 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/608 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/versioned-behaviours-cache` --- ### 📝 Commits (9) - [`78791b7`](https://github.com/horizon-rust/horizon/commit/78791b79ceb6c7c7dc6f1fa4b02e2d6e91f2f3d4) Cache resolved block behaviours across launches - [`1d3759b`](https://github.com/horizon-rust/horizon/commit/1d3759bb77dd7e9e6d08c689834001fbee4b3929) Drop a redundant binding flagged by clippy - [`0789bf0`](https://github.com/horizon-rust/horizon/commit/0789bf071926d6cf9ced552f916f1d4bc712f9c7) Keep the behaviours snapshot in the game folder, keyed to the build - [`2e98f6a`](https://github.com/horizon-rust/horizon/commit/2e98f6a18a8977f5a5c567f731370dbb4b2d197c) Let the behaviour profiler use a snapshot folder - [`02dce10`](https://github.com/horizon-rust/horizon/commit/02dce1093be2cbb0dcfc3f8bfd3267030facf176) Give the behaviour profiler its own name - [`4a83550`](https://github.com/horizon-rust/horizon/commit/4a8355047e92062322e0d5f81ac2f99319fbaedc) Merge main into perf/versioned-behaviours-cache - [`f0295c1`](https://github.com/horizon-rust/horizon/commit/f0295c167104a527f0ff1906f9c2a782ef21ecec) Merge remote-tracking branch 'pr/607' into HEAD - [`0a69d6b`](https://github.com/horizon-rust/horizon/commit/0a69d6b7bc248fc6c9c0348faf71e70098d82607) Merge main and #607 into perf/versioned-behaviours-cache - [`94209a3`](https://github.com/horizon-rust/horizon/commit/94209a32fc7c22f0fd00bab822947eb8ccbc7406) Merge main into perf/versioned-behaviours-cache ### 📊 Changes **9 files changed** (+1025 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+1 -0) 📝 `Cargo.lock` (+3 -0) 📝 `crates/horizon-client/src/game.rs` (+3 -0) 📝 `crates/horizon-world/Cargo.toml` (+3 -0) ➕ `crates/horizon-world/examples/behaviour_load_profile.rs` (+32 -0) 📝 `crates/horizon-world/src/level/data.rs` (+52 -7) ➕ `crates/horizon-world/src/level/data/cache.rs` (+867 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+7 -0) ➕ `tools/profile_behaviour_cache.py` (+57 -0) </details> ### 📄 Description `Behaviours::load` previously rebuilt the immutable behaviour tables from several JSON files, collision NBT and tag definitions on each launch. This PR persists the **resolved** tables in a versioned Postcard/LZ4 binary cache, so subsequent loads can restore the tables directly. The cache records state facts, collision shape grids and identity metadata, shape flags, resolved block and fluid tags, block metadata, sounds and item bindings. Registry-derived state indexing, dynamic support and runtime-only mutable fields are recreated on restore. Its header includes a format version, SHA-256 fingerprints of all consumed source resources and the caller's registry, and a payload checksum. Bad, old or missing caches fall back to the original loader; writes use a temporary file and atomic rename. Read-only resources still load normally. ### Startup loader benchmark Release-optimized `horizon-world` loader example with the prepared 26.3 resources. Each set has five independent processes, with three consecutive `Behaviours::load` calls per process. The baseline and optimized samples use the same prepared resource files (via a separate symlinked root for cache isolation). Numbers below are median elapsed milliseconds; the baseline is original `origin/main` at `f535d1b4` and the final optimized numbers use the Postcard cache on a warmed resource directory. | Behaviour-load call | Baseline | Warm cache | Reduction | | --- | ---: | ---: | ---: | | First call in process | 1,471.0 ms | 97.2 ms | 93.4% | | Second call | 1,371.2 ms | 92.9 ms | 93.2% | | Third call | 1,157.7 ms | 98.2 ms | 91.5% | **Cold-cache cost:** One observed first load, including the initial cache write, was **2,262 ms**. This is slower than the baseline first-call median; subsequent launches benefit. The baseline and optimized runs were measured during concurrent development builds, so CPU contention increased variance. These figures measure only behaviour loading; they are **not** full client time-to-title or time-to-world measurements. The requested `tools/profile_client_startup.py` did not exist on the starting branch; this PR adds a focused profiler plus a Rust example. It explicitly labels its scope. ### Validation - Two resource-backed cache tests passed with the final Postcard format: full-field snapshot roundtrip, cache hit, changed-resource invalidation, payload corruption, fallback and rewriting the cache. - All 89 `horizon-world` library tests passed before switching the cache payload from compressed JSON to Postcard; the cache-specific tests were rerun on Postcard and passed. - Rust source formatting, Python syntax and `git diff --check` passed. ### Limitations The cache must fingerprint the consumed resource files on each load, and its first write adds work to an uncached launch. Changes to resource packs or modded registries force rebuilding, but no separate modded-pack benchmark was run. The cache covers behaviour tables; other client startup stages and the registry loader are outside this change. --- <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: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#2671
No description provided.