[PR #6277] [MERGED] Resource packs: block sprites and OptiFine tiles decode on every thread #6761

Closed
opened 2026-11-03 06:26:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6277
Author: @some-du6e
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: packs/sprite-prefetch


📝 Commits (5)

  • 6bd9098 Resource packs: a benchmark of loading big packs, on generated files
  • 3ffb7b0 Resource packs: build a big pack's overlay on every thread
  • e0eb573 Pack bench: a bench the base can't build says so
  • 88cde78 Resource packs: decode block sprites and OptiFine tiles on every thread
  • 5543bff Sprites: the prefetch test inserts its tile after the names

📊 Changes

6 files changed (+742 additions, -24 deletions)

View changed files

➕ .github/workflows/pack-bench.yml (+61 -0)
➕ crates/horizon-client-render/examples/pack_load_bench.rs (+436 -0)
📝 crates/horizon-client-render/src/connected.rs (+11 -0)
📝 crates/horizon-client-render/src/models/catalog.rs (+16 -2)
📝 crates/horizon-client-render/src/packs.rs (+102 -20)
📝 crates/horizon-client-render/src/sprites.rs (+116 -2)

📄 Description

Part of making pack reloads as fast as PackForge and Quick Pack make them on Java. Block model baking and OptiFine connected textures added their textures one at a time, reading and decoding each PNG in turn. With a 64x pack, or one that ships thousands of CTM tiles, that was the slow part of the sprite stage. CTM tiles also skip the disk sprite cache, so they decoded again on every reload. The other OptiFine loaders on the way (CIT, ETF, EMF) will add many textures the same way, so they need a parallel path to hook into.

What I did:

  • Sprites::prefetch(root, names) decodes a list of sprite names (ns:path), or resource paths outside textures/, with par::par_map. It skips anything already a layer or in the disk cache. Each later insert/insert_file takes its decoded texture from there. A texture that fails to decode is left for the insert, which reports it as before. Unused prefetched textures are dropped in finish.
  • Block baking (models/catalog.rs) resolves every variant first, prefetches every texture the resolved models name, then bakes in the same order as before.
  • ConnectedTextures::load prefetches all its rules' tiles, under the names the insert loop gives them, before that loop.
  • Layers, layer order, pixels and flags stay identical, because inserts still happen in the loaders' own order. A test checks this: 40 textures of mixed sizes, two identical textures sharing a layer, a broken PNG, a missing texture and a CTM tile give the same layers, layer map, pixels, translucency and size with and without the prefetch.

How other OptiFine loaders hook in: call sprites.prefetch(root, names) with every texture you will insert, then insert as usual. I kept the change to connected.rs to that one call, so it sits next to the CTM PRs (#6198, #6250).

Numbers, from one pack load bench run (GitHub runner, 4 threads, median of 3). The base doesn't have prefetch, so both ways run in one binary:

Stage one by one prefetched
block sprites, 1100 at 64x, no disk cache 210 ms 122 ms
CTM tiles, 3300 at 64x 373 ms 226 ms

With the prefetch, a cold block-sprite load takes about as long as one from the disk cache (117 ms). What's left is laying out and resampling the layers, which is serial.

Depends on #6254 (the benchmark and its workflow come from there). Review only the last two commits.

Docs used: the PackForge and Quick Pack Modrinth pages (MIT; I read no code from either).

Checks: CI verify passed on the branch (formatting, clippy -D warnings, the workspace tests). I built nothing locally. The parity jobs need self-hosted runners and don't run from the fork. I couldn't run the block-model harnesses: they need the vanilla data in .local/, which this machine doesn't have.

Note

Filed by Opus 5.5 using 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/6277 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `packs/sprite-prefetch` --- ### 📝 Commits (5) - [`6bd9098`](https://github.com/horizon-rust/horizon/commit/6bd9098e3be2c87a085366219626f8738cd1c722) Resource packs: a benchmark of loading big packs, on generated files - [`3ffb7b0`](https://github.com/horizon-rust/horizon/commit/3ffb7b0663854981a3239003f3d0ed01a1d38305) Resource packs: build a big pack's overlay on every thread - [`e0eb573`](https://github.com/horizon-rust/horizon/commit/e0eb57399b59890ad1a9f80f3efaca529eaa0a12) Pack bench: a bench the base can't build says so - [`88cde78`](https://github.com/horizon-rust/horizon/commit/88cde780fbda9e16e9ee74bce2d9c5ea77c4db34) Resource packs: decode block sprites and OptiFine tiles on every thread - [`5543bff`](https://github.com/horizon-rust/horizon/commit/5543bffed58cd7a0c80f0906040decb4a55df74c) Sprites: the prefetch test inserts its tile after the names ### 📊 Changes **6 files changed** (+742 additions, -24 deletions) <details> <summary>View changed files</summary> ➕ `.github/workflows/pack-bench.yml` (+61 -0) ➕ `crates/horizon-client-render/examples/pack_load_bench.rs` (+436 -0) 📝 `crates/horizon-client-render/src/connected.rs` (+11 -0) 📝 `crates/horizon-client-render/src/models/catalog.rs` (+16 -2) 📝 `crates/horizon-client-render/src/packs.rs` (+102 -20) 📝 `crates/horizon-client-render/src/sprites.rs` (+116 -2) </details> ### 📄 Description Part of making pack reloads as fast as PackForge and Quick Pack make them on Java. Block model baking and OptiFine connected textures added their textures one at a time, reading and decoding each PNG in turn. With a 64x pack, or one that ships thousands of CTM tiles, that was the slow part of the sprite stage. CTM tiles also skip the disk sprite cache, so they decoded again on every reload. The other OptiFine loaders on the way (CIT, ETF, EMF) will add many textures the same way, so they need a parallel path to hook into. What I did: - `Sprites::prefetch(root, names)` decodes a list of sprite names (`ns:path`), or resource paths outside `textures/`, with `par::par_map`. It skips anything already a layer or in the disk cache. Each later `insert`/`insert_file` takes its decoded texture from there. A texture that fails to decode is left for the insert, which reports it as before. Unused prefetched textures are dropped in `finish`. - Block baking (`models/catalog.rs`) resolves every variant first, prefetches every texture the resolved models name, then bakes in the same order as before. - `ConnectedTextures::load` prefetches all its rules' tiles, under the names the insert loop gives them, before that loop. - Layers, layer order, pixels and flags stay identical, because inserts still happen in the loaders' own order. A test checks this: 40 textures of mixed sizes, two identical textures sharing a layer, a broken PNG, a missing texture and a CTM tile give the same layers, layer map, pixels, translucency and size with and without the prefetch. How other OptiFine loaders hook in: call `sprites.prefetch(root, names)` with every texture you will insert, then insert as usual. I kept the change to `connected.rs` to that one call, so it sits next to the CTM PRs (#6198, #6250). Numbers, from one `pack load bench` run (GitHub runner, 4 threads, median of 3). The base doesn't have `prefetch`, so both ways run in one binary: | Stage | one by one | prefetched | |---|---:|---:| | block sprites, 1100 at 64x, no disk cache | 210 ms | 122 ms | | CTM tiles, 3300 at 64x | 373 ms | 226 ms | With the prefetch, a cold block-sprite load takes about as long as one from the disk cache (117 ms). What's left is laying out and resampling the layers, which is serial. Depends on #6254 (the benchmark and its workflow come from there). Review only the last two commits. Docs used: the PackForge and Quick Pack Modrinth pages (MIT; I read no code from either). Checks: CI `verify` passed on the branch (formatting, clippy `-D warnings`, the workspace tests). I built nothing locally. The parity jobs need self-hosted runners and don't run from the fork. I couldn't run the block-model harnesses: they need the vanilla data in `.local/`, which this machine doesn't have. > [!NOTE] > Filed by Opus 5.5 using 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 06:26:14 +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#6761
No description provided.