[PR #598] [CLOSED] Cache resolved block models across transformed blockstate variants #2664

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/598
Author: @rdbtCVS
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: perf/cache-block-model-geometry-20261017


📝 Commits (2)

  • ae6c96f perf: reuse resolved block models across variants
  • 44eccba test: verify resolved model parity and add paired startup profiling

📊 Changes

3 files changed (+205 additions, -3 deletions)

View changed files

📝 crates/horizon-client/examples/model_states_bench.rs (+96 -2)
📝 crates/horizon-client/src/models/catalog.rs (+9 -1)
➕ tools/profile_client_startup.py (+100 -0)

📄 Description

Change

StateModels::from_facts_with_models now resolves each distinct model identifier only once per preparation. Rotations and UV-lock still bake separately; their faces, sprite layers, opacity/translucency and cube geometry metadata continue through the original path. The resolved-model cache is local to each catalog construction and cannot survive resource-pack or mod reloads. Existing baked variant cache handles reuse during rendering.

Correctness

  • Rebased on main e422bd13; candidate commits ae6c96f6 and 44eccba6.
  • cargo test -p horizon-client --example model_states_bench --no-default-features -- --nocapture: 3 passed. Includes model replacement under the same root, inherited parent geometry and chained texture aliases, weighted multipart variants, rotations/UV-lock, direct-bake face equality and sprite properties.
  • Initial parallel test failures were a pre-existing fixture collision caused by temp paths based only on PID; fixed with unique per-process fixture IDs.
  • Full real-resource fingerprint parity across two positions per registry state and item baking: both binaries 86a447cfd3f535c2.
  • cargo fmt --all -- --check, git diff --check, and python3 -m py_compile tools/profile_client_startup.py passed.

Startup benchmark and limitations

Built the baseline executable from unchanged main e422bd13 and candidate executable from this branch, both cargo build --profile fast -p horizon-client --example model_library_bench, copied to distinct immutable /tmp paths. Used tools/profile_client_startup.py --kind models --compare-binary BASELINE --binary CANDIDATE --warmups 2 --repeats 5 --parity on identical local prepared 26.3 resources. Separate fresh processes, alternating order, file caches allowed to warm. No compilation initiated by the profiler.

Metric Baseline median (min–max) ms Candidate median (min–max) ms
Block preparation 2,568.528 (1,367.397–13,053.763) 10,157.433 (2,839.168–16,300.586)
Item preparation 262.105 (182.745–821.775) 2,440.641 (183.196–4,265.972)
Combined 2,751.273 (1,551.636–13,809.311) 12,598.075 (3,152.313–20,491.687)

No speedup is established. Concurrent unrelated builds, extremely wide run-to-run variance, and unexpected item-preparation swings make these measurements unsuitable for attributing the observed difference to the resolved-model cache. The profiler measures Assets::load and item preparation, not the isolated ~146 ms models::prepare_with_models span or first rendered frame. Changes to compiled blockstate variant or derived geometry caching have therefore not been made: the existing implementation already caches baked (model, rotation, uv-lock) variants, and an additional optimization is not justified by current profiling.

Remaining before ready for review

  • Repeat benchmark on a quiet host with controlled CPU frequency and temperature and a stage-level timer around models::prepare_with_models; collect adequately stable paired samples.
  • Run full resource-pack and mod override/reload integration tests beyond the direct fixture and full default-resource fingerprint.
  • Confirm the resolved-model cache has a measurable net improvement rather than assuming one.

This PR intentionally remains draft.


🔄 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/598 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/cache-block-model-geometry-20261017` --- ### 📝 Commits (2) - [`ae6c96f`](https://github.com/horizon-rust/horizon/commit/ae6c96f6c024d76f3a2278a8c18627e089226c21) perf: reuse resolved block models across variants - [`44eccba`](https://github.com/horizon-rust/horizon/commit/44eccba631e3d3248f838477b7fbed897fd51797) test: verify resolved model parity and add paired startup profiling ### 📊 Changes **3 files changed** (+205 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/model_states_bench.rs` (+96 -2) 📝 `crates/horizon-client/src/models/catalog.rs` (+9 -1) ➕ `tools/profile_client_startup.py` (+100 -0) </details> ### 📄 Description ## Change `StateModels::from_facts_with_models` now resolves each distinct model identifier only once per preparation. Rotations and UV-lock still bake separately; their faces, sprite layers, opacity/translucency and cube geometry metadata continue through the original path. The resolved-model cache is local to each catalog construction and cannot survive resource-pack or mod reloads. Existing baked variant cache handles reuse during rendering. ## Correctness - Rebased on `main` e422bd13; candidate commits ae6c96f6 and 44eccba6. - `cargo test -p horizon-client --example model_states_bench --no-default-features -- --nocapture`: **3 passed**. Includes model replacement under the same root, inherited parent geometry and chained texture aliases, weighted multipart variants, rotations/UV-lock, direct-bake face equality and sprite properties. - Initial parallel test failures were a pre-existing fixture collision caused by temp paths based only on PID; fixed with unique per-process fixture IDs. - Full real-resource fingerprint parity across two positions per registry state and item baking: both binaries `86a447cfd3f535c2`. - `cargo fmt --all -- --check`, `git diff --check`, and `python3 -m py_compile tools/profile_client_startup.py` passed. ## Startup benchmark and limitations Built the baseline executable from unchanged `main` e422bd13 and candidate executable from this branch, both `cargo build --profile fast -p horizon-client --example model_library_bench`, copied to distinct immutable `/tmp` paths. Used `tools/profile_client_startup.py --kind models --compare-binary BASELINE --binary CANDIDATE --warmups 2 --repeats 5 --parity` on identical local prepared 26.3 resources. Separate fresh processes, alternating order, file caches allowed to warm. No compilation initiated by the profiler. | Metric | Baseline median (min–max) ms | Candidate median (min–max) ms | | --- | ---: | ---: | | Block preparation | 2,568.528 (1,367.397–13,053.763) | 10,157.433 (2,839.168–16,300.586) | | Item preparation | 262.105 (182.745–821.775) | 2,440.641 (183.196–4,265.972) | | Combined | 2,751.273 (1,551.636–13,809.311) | 12,598.075 (3,152.313–20,491.687) | **No speedup is established.** Concurrent unrelated builds, extremely wide run-to-run variance, and unexpected item-preparation swings make these measurements unsuitable for attributing the observed difference to the resolved-model cache. The profiler measures `Assets::load` and item preparation, *not* the isolated ~146 ms `models::prepare_with_models` span or first rendered frame. Changes to compiled blockstate variant or derived geometry caching have therefore **not** been made: the existing implementation already caches baked `(model, rotation, uv-lock)` variants, and an additional optimization is not justified by current profiling. ## Remaining before ready for review - Repeat benchmark on a quiet host with controlled CPU frequency and temperature and a stage-level timer around `models::prepare_with_models`; collect adequately stable paired samples. - Run full resource-pack and mod override/reload integration tests beyond the direct fixture and full default-resource fingerprint. - Confirm the resolved-model cache has a measurable net improvement rather than assuming one. This PR intentionally remains **draft**. --- <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#2664
No description provided.