[PR #3015] [MERGED] perf(assets): keep decoded block sprites on disk between launches #4756

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3015
Author: @DanielGodriNeto
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: perf/sprite-disk-cache


📝 Commits (3)

  • e14d6f7 perf(assets): keep decoded block sprites on disk between launches
  • 5edfd95 Sprite cache test: escape the corrupt header's bytes
  • 2d966fb Merge main into this branch after the render crate split (#3186)

📊 Changes

6 files changed (+488 additions, -15 deletions)

View changed files

📝 crates/horizon-client-render/src/assets.rs (+2 -1)
📝 crates/horizon-client-render/src/atlas_sources.rs (+8 -1)
📝 crates/horizon-client-render/src/lib.rs (+1 -0)
➕ crates/horizon-client-render/src/sprite_cache.rs (+345 -0)
📝 crates/horizon-client-render/src/sprites.rs (+74 -13)
➕ crates/horizon-client/examples/sprite_cache_parity.rs (+58 -0)

📄 Description

🤖 Opened by Daniel's AI agent (Claude Code), not by Daniel himself.

What

RenderAssets::load decodes ~1300 block PNGs and their .mcmeta on every launch. This keeps the decoded result in one cache file (horizon-sprites.cache, ~2 MB) next to the prepared resources and reads it back on the next launch. It also lists the textures trees with the file type that comes with the directory listing instead of one stat per entry (atlas_sources.rs).

Safety

The cache is only used while a fingerprint still matches: the relative path, size and modification time of every file under assets/*/textures, plus a format version. A new, removed or changed file, a different version, or a missing, truncated or corrupt cache file means the normal decoding path. Writing the cache is best effort (temp file + rename); a failed write only costs the next launch the decoding. Known limit: a file replaced by one with the same size and mtime is not noticed (same as any mtime-keyed cache; hashing 650 MB of content would cost the gain).

Parity

cargo run --profile fast -p horizon-client --example sprite_cache_parity -- <resources> compares the pixel buffer, layers, mips, animation frames and blend data between decoding and reading from the cache: identical. Unit tests cover the round trip, wrong fingerprint, every truncation, trailing bytes, a changed or new texture invalidating, and a corrupt or deleted cache file.

Evidence

model_library_bench (Assets + RenderAssets + ItemRenderer), fresh process per round, below-normal priority, 6 interleaved ABAB rounds per batch with A/A in between, 647 MB of resources: total 779 -> 648 ms and 771 -> 641 ms in two batches (about -130 ms, -16%); A/A noise 1-3 ms. This is the isolated load benchmark, not the full world join, so I claim no join time or FPS change.

pr_ready

Scope warning: 503 lines of code (the parity example is 58 of them). pr_ready.py --quick --base upstream/main on Windows: public tree, rustfmt, clippy and doc tests pass. 2 tests in horizon-client fail (crash::tests::stacks_start_at_the_panicking_frame, save::tests::session_lock_is_exclusive) and some Python tests fail; none is in code this PR touches. The vanilla harnesses were not run here (--quick).

🤖 Generated with Claude Code


🔄 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/3015 **Author:** [@DanielGodriNeto](https://github.com/DanielGodriNeto) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/sprite-disk-cache` --- ### 📝 Commits (3) - [`e14d6f7`](https://github.com/horizon-rust/horizon/commit/e14d6f79b1e0aac1dba53a3e4d2802fc16fb5635) perf(assets): keep decoded block sprites on disk between launches - [`5edfd95`](https://github.com/horizon-rust/horizon/commit/5edfd95da620cad94607db8fa7e1c8d2519e306a) Sprite cache test: escape the corrupt header's bytes - [`2d966fb`](https://github.com/horizon-rust/horizon/commit/2d966fb3ad2bb7170bb20b270b0836df86e7ece9) Merge main into this branch after the render crate split (#3186) ### 📊 Changes **6 files changed** (+488 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/assets.rs` (+2 -1) 📝 `crates/horizon-client-render/src/atlas_sources.rs` (+8 -1) 📝 `crates/horizon-client-render/src/lib.rs` (+1 -0) ➕ `crates/horizon-client-render/src/sprite_cache.rs` (+345 -0) 📝 `crates/horizon-client-render/src/sprites.rs` (+74 -13) ➕ `crates/horizon-client/examples/sprite_cache_parity.rs` (+58 -0) </details> ### 📄 Description > 🤖 Opened by Daniel's AI agent (Claude Code), not by Daniel himself. ## What `RenderAssets::load` decodes ~1300 block PNGs and their `.mcmeta` on every launch. This keeps the decoded result in one cache file (`horizon-sprites.cache`, ~2 MB) next to the prepared resources and reads it back on the next launch. It also lists the `textures` trees with the file type that comes with the directory listing instead of one `stat` per entry (`atlas_sources.rs`). ## Safety The cache is only used while a fingerprint still matches: the relative path, size and modification time of every file under `assets/*/textures`, plus a format version. A new, removed or changed file, a different version, or a missing, truncated or corrupt cache file means the normal decoding path. Writing the cache is best effort (temp file + rename); a failed write only costs the next launch the decoding. Known limit: a file replaced by one with the same size and mtime is not noticed (same as any mtime-keyed cache; hashing 650 MB of content would cost the gain). ## Parity `cargo run --profile fast -p horizon-client --example sprite_cache_parity -- <resources>` compares the pixel buffer, layers, mips, animation frames and blend data between decoding and reading from the cache: identical. Unit tests cover the round trip, wrong fingerprint, every truncation, trailing bytes, a changed or new texture invalidating, and a corrupt or deleted cache file. ## Evidence `model_library_bench` (Assets + RenderAssets + ItemRenderer), fresh process per round, below-normal priority, 6 interleaved ABAB rounds per batch with A/A in between, 647 MB of resources: total 779 -> 648 ms and 771 -> 641 ms in two batches (about -130 ms, -16%); A/A noise 1-3 ms. This is the isolated load benchmark, not the full world join, so I claim no join time or FPS change. ## pr_ready Scope warning: 503 lines of code (the parity example is 58 of them). `pr_ready.py --quick --base upstream/main` on Windows: public tree, rustfmt, clippy and doc tests pass. 2 tests in horizon-client fail (`crash::tests::stacks_start_at_the_panicking_frame`, `save::tests::session_lock_is_exclusive`) and some Python tests fail; none is in code this PR touches. The vanilla harnesses were not run here (`--quick`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:07:42 +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#4756
No description provided.