[PR #610] [CLOSED] perf: cache prepared resource-pack face geometry #2675

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

📋 Pull Request Information

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

Base: main ← Head: perf/pack-derived-cache-20261017


📝 Commits (3)

  • 4833508 perf: cache prepared resource-pack face geometry
  • 978d4d8 perf: persist full mesh tables and validate pack inputs
  • 612fc31 perf: harden mesh snapshot invalidation and startup profiling

📊 Changes

11 files changed (+1017 additions, -19 deletions)

View changed files

📝 Cargo.lock (+56 -0)
📝 crates/horizon-client/Cargo.toml (+1 -0)
📝 crates/horizon-client/src/game.rs (+33 -15)
➕ crates/horizon-client/src/game/pack_cache.rs (+450 -0)
📝 crates/horizon-client/src/mesher.rs (+48 -2)
📝 crates/horizon-client/src/mesher/leaf_culling_tests.rs (+82 -0)
📝 crates/horizon-core/src/geometry/shape.rs (+6 -0)
📝 crates/horizon-world/Cargo.toml (+1 -0)
📝 crates/horizon-world/src/block_render.rs (+168 -0)
📝 crates/horizon-world/src/fluid.rs (+3 -2)
➕ tools/profile_client_startup.py (+169 -0)

📄 Description

PackResources::load rebuilt derived face visibility and per-state mesh tables on each launch. This PR persists the complete immutable MeshTables representation (render facts, face geometry, fluid sprite layers), retaining the original loader for absent, corrupted or incompatible cache entries and reinitializing runtime pair caches after restoration.

Resource-pack and mod compatibility

Cache format v3 includes magic/version, SHA-256 payload checksum, bounded snapshot size, and validated per-state dimensions. The key tracks the canonical effective root, source stamps for occlusion.nbt, render-definitions.json, facts.json, gameplay-facts.json, block-behaviours.json, and block-tags.json; the published resource-pack overlay marker (pack additions/removals/order and input edits), mod-content marker, resolved sprite layers, and the actual in-memory blocks_fluid_flow set (which may survive pack reloads). Unix ctime/inode changes catch timestamp-preserving rewrites; other platforms hash source file contents. Input identity is checked again before accepting a hit or publishing a rebuild. Writers use unique, exclusive temporary files, sync the file, then rename; failed/interrupted writes cause misses, and Windows replaces an existing invalid snapshot safely. Unexpected cache errors fall back to rebuilding.

An integration test using actual prepared 26.3 resources creates multiple real folder packs, tests additions/removals/reordering and edits to model files in a reused overlay root, then overlays two content mods with a shared root. Further tests cover source stamps, resolved sprite remapping and fluid-flow changes, marker changes, explicit version mismatch, checksum tampering, abandoned temporary files, and recovery after a damaged published snapshot. Real-resource mesh-table round-trip checks compare all block states and byte-for-byte solid/translucent terrain vertices and visibility for representative opaque, cutout, fluid and translucent neighbours.

Performance (same optimized binary, prepared 26.3 resources)

python3 tools/profile_client_startup.py --binary target/fast/horizon-client --resources ../../.local/horizon-client/26.3 --repeats 7 --timeout 120 creates one fresh cache, then alternates 7 disabled-cache and 7 cached launches in reversed order each pair. Numbers below are medians, with median absolute deviation (MAD) and min–max in brackets where useful:

Stage Uncached Cached Difference
Mesh-table build/restore 178.03 ms (MAD 33.09) 64.60 ms (MAD 2.09) -113.43 ms (63.7%)
Pack-loading interval, including light tables 380 ms (310–470) 270 ms (250–330) -110 ms (28.9%)
Total elapsed through PackResources::load 1476.79 ms (MAD 42.12) 1483.63 ms (MAD 115.64) +6.84 ms (within variability; no overall gain demonstrated)
Item-renderer setup 65.76 ms 54.52 ms no change implemented
Other PackResources fields 50.17 ms 58.49 ms no change implemented

First-launch cache creation was 1532.78 ms elapsed, 380 ms pack interval and 158.95 ms mesh-table build (plus cache write); all 7 cached samples confirmed hits. Sequential seven-run measurements also saw mesh loading improve, but total elapsed was variable. The source of the ~50–60 ms item/auxiliary stages has not justified another persistent cache. Raw measurement reports: /tmp/pack-render-hardened.json (sequential) and /tmp/pack-render-interleaved.json (balanced) on the profiling host.

A bounded one-frame offscreen full-client attempt measured first launch 5288.22 ms and uncached 4815.83 ms, but the cached sample failed at GPU initialization with Parent device is lost on Vulkan, after pack loading. Thus no reliable full-client speedup is claimed. Stage measurements end before GPU/window/world startup and are affected by host workload and OS caches; the pack interval comes from cumulative timestamps rounded to ~10 ms. This is not an exhaustive third-party mod matrix.

Validation

  • cargo build --offline --profile fast -p horizon-client --bin horizon-client passed.
  • cargo clippy --offline -p horizon-client --bin horizon-client -- -D warnings passed.
  • cargo test --offline -p horizon-client --bin horizon-client pack_cache::tests (5 integration/invalidation/recovery tests) passed.
  • cargo test --offline -p horizon-client --lib cached_tables_match_fresh_render_facts (all states + terrain-vertex parity) passed.
  • cargo fmt --all -- --check, git diff --check, python3 -m py_compile tools/profile_client_startup.py passed.
  • Prior commit's GitHub verify CI was successful; latest CI is pending.

Remaining limitations: other asset/atlas and item preparation still happens, runtime-only rendering features remain outside the cached tables, and cache format version must change when snapshot interpretation changes. This snapshot is reusable only while its resource dependencies and effective in-memory inputs match.


🔄 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/610 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/pack-derived-cache-20261017` --- ### 📝 Commits (3) - [`4833508`](https://github.com/horizon-rust/horizon/commit/4833508dd176e14fac81f73733ba27456ccf3155) perf: cache prepared resource-pack face geometry - [`978d4d8`](https://github.com/horizon-rust/horizon/commit/978d4d8704017190865e77d4b7c4cf15251d8a89) perf: persist full mesh tables and validate pack inputs - [`612fc31`](https://github.com/horizon-rust/horizon/commit/612fc3165f64a652dc2fd4b55f2ae214a4387366) perf: harden mesh snapshot invalidation and startup profiling ### 📊 Changes **11 files changed** (+1017 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+56 -0) 📝 `crates/horizon-client/Cargo.toml` (+1 -0) 📝 `crates/horizon-client/src/game.rs` (+33 -15) ➕ `crates/horizon-client/src/game/pack_cache.rs` (+450 -0) 📝 `crates/horizon-client/src/mesher.rs` (+48 -2) 📝 `crates/horizon-client/src/mesher/leaf_culling_tests.rs` (+82 -0) 📝 `crates/horizon-core/src/geometry/shape.rs` (+6 -0) 📝 `crates/horizon-world/Cargo.toml` (+1 -0) 📝 `crates/horizon-world/src/block_render.rs` (+168 -0) 📝 `crates/horizon-world/src/fluid.rs` (+3 -2) ➕ `tools/profile_client_startup.py` (+169 -0) </details> ### 📄 Description `PackResources::load` rebuilt derived face visibility and per-state mesh tables on each launch. This PR persists the complete immutable `MeshTables` representation (render facts, face geometry, fluid sprite layers), retaining the original loader for absent, corrupted or incompatible cache entries and reinitializing runtime pair caches after restoration. ## Resource-pack and mod compatibility Cache format v3 includes magic/version, SHA-256 payload checksum, bounded snapshot size, and validated per-state dimensions. The key tracks the canonical effective root, source stamps for `occlusion.nbt`, `render-definitions.json`, `facts.json`, `gameplay-facts.json`, `block-behaviours.json`, and `block-tags.json`; the published resource-pack overlay marker (pack additions/removals/order and input edits), mod-content marker, resolved sprite layers, and the actual in-memory `blocks_fluid_flow` set (which may survive pack reloads). Unix ctime/inode changes catch timestamp-preserving rewrites; other platforms hash source file contents. Input identity is checked again before accepting a hit or publishing a rebuild. Writers use unique, exclusive temporary files, sync the file, then rename; failed/interrupted writes cause misses, and Windows replaces an existing invalid snapshot safely. Unexpected cache errors fall back to rebuilding. An integration test using actual prepared 26.3 resources creates multiple real folder packs, tests additions/removals/reordering and edits to model files in a reused overlay root, then overlays two content mods with a shared root. Further tests cover source stamps, resolved sprite remapping and fluid-flow changes, marker changes, explicit version mismatch, checksum tampering, abandoned temporary files, and recovery after a damaged published snapshot. Real-resource mesh-table round-trip checks compare all block states and byte-for-byte solid/translucent terrain vertices and visibility for representative opaque, cutout, fluid and translucent neighbours. ## Performance (same optimized binary, prepared 26.3 resources) `python3 tools/profile_client_startup.py --binary target/fast/horizon-client --resources ../../.local/horizon-client/26.3 --repeats 7 --timeout 120` creates one fresh cache, then alternates 7 disabled-cache and 7 cached launches in reversed order each pair. Numbers below are medians, with median absolute deviation (MAD) and min–max in brackets where useful: | Stage | Uncached | Cached | Difference | | --- | ---: | ---: | ---: | | Mesh-table build/restore | 178.03 ms (MAD 33.09) | 64.60 ms (MAD 2.09) | -113.43 ms (63.7%) | | Pack-loading interval, including light tables | 380 ms (310–470) | 270 ms (250–330) | -110 ms (28.9%) | | Total elapsed through PackResources::load | 1476.79 ms (MAD 42.12) | 1483.63 ms (MAD 115.64) | +6.84 ms (within variability; no overall gain demonstrated) | | Item-renderer setup | 65.76 ms | 54.52 ms | no change implemented | | Other PackResources fields | 50.17 ms | 58.49 ms | no change implemented | First-launch cache creation was 1532.78 ms elapsed, 380 ms pack interval and 158.95 ms mesh-table build (plus cache write); all 7 cached samples confirmed hits. Sequential seven-run measurements also saw mesh loading improve, but total elapsed was variable. The source of the ~50–60 ms item/auxiliary stages has not justified another persistent cache. Raw measurement reports: `/tmp/pack-render-hardened.json` (sequential) and `/tmp/pack-render-interleaved.json` (balanced) on the profiling host. A bounded one-frame offscreen full-client attempt measured first launch 5288.22 ms and uncached 4815.83 ms, but the cached sample failed at GPU initialization with `Parent device is lost` on Vulkan, after pack loading. Thus no reliable full-client speedup is claimed. Stage measurements end before GPU/window/world startup and are affected by host workload and OS caches; the pack interval comes from cumulative timestamps rounded to ~10 ms. This is not an exhaustive third-party mod matrix. ## Validation - `cargo build --offline --profile fast -p horizon-client --bin horizon-client` passed. - `cargo clippy --offline -p horizon-client --bin horizon-client -- -D warnings` passed. - `cargo test --offline -p horizon-client --bin horizon-client pack_cache::tests` (5 integration/invalidation/recovery tests) passed. - `cargo test --offline -p horizon-client --lib cached_tables_match_fresh_render_facts` (all states + terrain-vertex parity) passed. - `cargo fmt --all -- --check`, `git diff --check`, `python3 -m py_compile tools/profile_client_startup.py` passed. - Prior commit's GitHub verify CI was successful; latest CI is pending. Remaining limitations: other asset/atlas and item preparation still happens, runtime-only rendering features remain outside the cached tables, and cache format version must change when snapshot interpretation changes. This snapshot is reusable only while its resource dependencies and effective in-memory inputs match. --- <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:08 +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#2675
No description provided.