[PR #597] [CLOSED] Cache validated block registry for faster client asset loading #2663

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/597
Author: @rdbtCVS
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: perf/precomputed-assets-registry-20261017


📝 Commits (3)

  • 1e73429 Cache validated block registry NBT from resource facts
  • 7f0653a Avoid redundant registry reconstruction and document benchmarks
  • 568a38b Validate registry cache integrity and benchmark typed state loading

📊 Changes

5 files changed (+782 additions, -23 deletions)

View changed files

📝 crates/horizon-client/src/assets.rs (+541 -19)
📝 crates/horizon-world/src/chunk.rs (+1 -1)
📝 crates/horizon-world/src/registry.rs (+38 -3)
➕ docs/assets-registry-cache-benchmark.md (+122 -0)
➕ tools/profile_client_startup.py (+80 -0)

📄 Description

Result

Assets::load constructs a version-pinned block registry from facts.json. This PR adds a typed, validated persistent representation for repeated launches and changes the internal state-to-ID lookup from BTreeMap to HashMap without changing the ordered state vector, numeric IDs, default IDs, property values, or resource-pack/mod behaviour.

A second, correctly configured benchmark pass resolved the earlier conflicting results: the unoptimised debug-profile registry microbenchmark had falsely suggested that cache decoding was slower. Two repetitions with an optimised fast test binary measured warm typed-cache loading at 50–51 ms, versus 133–135 ms for direct conversion with the same lookup implementation: ~62% lower median registry-stage cost. This explains the observed loader improvement and supports retaining the cache.

Repeated, matched full-loader measurements

Twelve fresh processes per condition, prebuilt fast binaries, pinned Minecraft 26.3 resources, same disposable root, no concurrent cargo or rustc at benchmark boundaries. total_ms includes Assets::load plus item preparation; it does not measure GPU/GUI startup or time to first rendered frame.

Variant Assets median Assets + items median Total MAD Total range
Original, ordered lookup 463.542 ms 499.497 ms 11.423 ms 486.164–524.847 ms
Direct conversion, faster lookup (experimental comparator) 485.102 ms 521.024 ms 14.877 ms 500.679–544.611 ms
Typed cache, cold creation 478.352 ms 513.121 ms 6.943 ms 504.239–531.936 ms
Typed cache, warm reuse 389.453 ms 430.217 ms 18.857 ms 404.564–484.007 ms

Warm reuse improved total median by 13.9% versus original and 17.4% versus the no-cache HashMap candidate in this controlled batch. Creating the cache was 2.7% slower than original. An earlier ten-sample batch (517.266 ms original versus 428.983 ms warm cache) supports the warm-start direction. Results are host-specific; a 17% figure from an earlier comparison must not be attributed entirely to the lookup structure.

Two optimized registry microbenchmark repetitions, each 20 alternating samples:

Run Direct NBT conversion Cold creation Warm decoding
First (median) 135.260 ms 150.230 ms 51.210 ms
Repeat (median) 132.631 ms 147.808 ms 50.262 ms

For methodology, all sample ranges, config, reproducible commands, and remaining limits see benchmark report and raw loader JSON.

Correctness and compatibility

  • Existing source facts.json is always parsed and resource data-version checked. A missing, stale, oversized, invalid, truncated or unreadable cache invokes the original JSON-to-NBT parser and its errors.
  • Each cache is versioned and contains source/payload SHA-256 values. Decoding is bounded and checks duplicates, UTF-8, default IDs, block coverage and trailing data. A newly added regression constructs a semantically inconsistent payload with a recomputed payload checksum to verify that it is rejected.
  • Concurrent writers publish through unique create_new temporary paths with file synchronization and same-directory atomic rename; failed writes do not affect the load. Read-only resource roots continue to work.
  • Content-mod overlays rebuild at launch, so cache persistence is outside their disposable overlay and keyed to modified facts.json. Resource-pack model reloads use the existing registry.
  • Ordered states, state IDs, names, property values and default IDs are checked against the original conversion; duplicate states and invalid defaults retain prior validation.

Checks and limits

cargo fmt --all -- --check, cargo check --offline -p horizon-client --lib, git diff --check, eight cache regression tests (one ignored benchmark), real resource-backed content-mod integration and world registry parity all passed. The benchmark test was also executed twice in fast profile with absolute prepared-resource paths.

The first load after cache invalidation costs about 15 ms more at the isolated registry stage. No full graphical client time-to-first-frame measurement, power-loss fault injection, or multi-host benchmark has been completed. The no-cache HashMap full-loader comparator was a temporary experimental variant; unlike the three committed builds and the registry microbenchmark, it is not distributed as a separate commit. That limits independent reproduction of that one comparison.


🔄 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/597 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/precomputed-assets-registry-20261017` --- ### 📝 Commits (3) - [`1e73429`](https://github.com/horizon-rust/horizon/commit/1e734293f8fa43f6b6fb2f0003b6851365215b1f) Cache validated block registry NBT from resource facts - [`7f0653a`](https://github.com/horizon-rust/horizon/commit/7f0653a716f656c3fdc2e8b317348ee5e4cbe677) Avoid redundant registry reconstruction and document benchmarks - [`568a38b`](https://github.com/horizon-rust/horizon/commit/568a38b5ecb3bf1960b1481963c91abbde2e838f) Validate registry cache integrity and benchmark typed state loading ### 📊 Changes **5 files changed** (+782 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/assets.rs` (+541 -19) 📝 `crates/horizon-world/src/chunk.rs` (+1 -1) 📝 `crates/horizon-world/src/registry.rs` (+38 -3) ➕ `docs/assets-registry-cache-benchmark.md` (+122 -0) ➕ `tools/profile_client_startup.py` (+80 -0) </details> ### 📄 Description ## Result `Assets::load` constructs a version-pinned block registry from `facts.json`. This PR adds a typed, validated persistent representation for repeated launches and changes the internal state-to-ID lookup from `BTreeMap` to `HashMap` without changing the ordered state vector, numeric IDs, default IDs, property values, or resource-pack/mod behaviour. A second, correctly configured benchmark pass resolved the earlier conflicting results: **the unoptimised debug-profile registry microbenchmark had falsely suggested that cache decoding was slower.** Two repetitions with an optimised `fast` test binary measured warm typed-cache loading at 50–51 ms, versus 133–135 ms for direct conversion with the same lookup implementation: ~62% lower median registry-stage cost. This explains the observed loader improvement and supports retaining the cache. ## Repeated, matched full-loader measurements Twelve fresh processes per condition, prebuilt `fast` binaries, pinned Minecraft 26.3 resources, same disposable root, no concurrent `cargo` or `rustc` at benchmark boundaries. `total_ms` includes `Assets::load` plus item preparation; it does **not** measure GPU/GUI startup or time to first rendered frame. | Variant | Assets median | Assets + items median | Total MAD | Total range | | --- | ---: | ---: | ---: | ---: | | Original, ordered lookup | 463.542 ms | **499.497 ms** | 11.423 ms | 486.164–524.847 ms | | Direct conversion, faster lookup (experimental comparator) | 485.102 ms | 521.024 ms | 14.877 ms | 500.679–544.611 ms | | Typed cache, cold creation | 478.352 ms | **513.121 ms** | 6.943 ms | 504.239–531.936 ms | | Typed cache, warm reuse | **389.453 ms** | **430.217 ms** | 18.857 ms | 404.564–484.007 ms | Warm reuse improved total median by **13.9%** versus original and **17.4%** versus the no-cache HashMap candidate in this controlled batch. Creating the cache was **2.7% slower** than original. An earlier ten-sample batch (517.266 ms original versus 428.983 ms warm cache) supports the warm-start direction. Results are host-specific; a 17% figure from an earlier comparison must not be attributed entirely to the lookup structure. Two optimized registry microbenchmark repetitions, each 20 alternating samples: | Run | Direct NBT conversion | Cold creation | Warm decoding | | --- | ---: | ---: | ---: | | First (median) | 135.260 ms | 150.230 ms | **51.210 ms** | | Repeat (median) | 132.631 ms | 147.808 ms | **50.262 ms** | For methodology, all sample ranges, config, reproducible commands, and remaining limits see [benchmark report](https://github.com/rdbtCVS/horizon/blob/perf/precomputed-assets-registry-20261017/docs/assets-registry-cache-benchmark.md) and [raw loader JSON](https://github.com/rdbtCVS/horizon/blob/perf/precomputed-assets-registry-20261017/docs/benchmarks/pr597-registry-startup-20261017.json). ## Correctness and compatibility - Existing source `facts.json` is always parsed and resource data-version checked. A missing, stale, oversized, invalid, truncated or unreadable cache invokes the original JSON-to-NBT parser and its errors. - Each cache is versioned and contains source/payload SHA-256 values. Decoding is bounded and checks duplicates, UTF-8, default IDs, block coverage and trailing data. A newly added regression constructs a semantically inconsistent payload *with a recomputed payload checksum* to verify that it is rejected. - Concurrent writers publish through unique `create_new` temporary paths with file synchronization and same-directory atomic rename; failed writes do not affect the load. Read-only resource roots continue to work. - Content-mod overlays rebuild at launch, so cache persistence is outside their disposable overlay and keyed to modified `facts.json`. Resource-pack model reloads use the existing registry. - Ordered states, state IDs, names, property values and default IDs are checked against the original conversion; duplicate states and invalid defaults retain prior validation. ## Checks and limits `cargo fmt --all -- --check`, `cargo check --offline -p horizon-client --lib`, `git diff --check`, eight cache regression tests (one ignored benchmark), real resource-backed content-mod integration and world registry parity all passed. The benchmark test was also executed twice in `fast` profile with absolute prepared-resource paths. The first load after cache invalidation costs about 15 ms more at the isolated registry stage. No full graphical client time-to-first-frame measurement, power-loss fault injection, or multi-host benchmark has been completed. The no-cache HashMap full-loader comparator was a temporary experimental variant; unlike the three committed builds and the registry microbenchmark, it is not distributed as a separate commit. That limits independent reproduction of that one comparison. --- <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:03 +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#2663
No description provided.