[PR #1191] [MERGED] Load time: build a pack's content root and load its sprites and models in parallel #3407

Closed
opened 2026-11-03 04:09:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1191
Author: @ludovic111
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @ludovic111

Base: main ← Head: perf/mod-content-build


📝 Commits (1)

  • 8a03758 Load time: build a pack's content root and load its sprites and models in parallel

📊 Changes

6 files changed (+216 additions, -73 deletions)

View changed files

📝 crates/horizon-client/src/hud.rs (+39 -20)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/mod_content.rs (+63 -23)
📝 crates/horizon-client/src/model_library.rs (+22 -7)
➕ crates/horizon-client/src/par.rs (+54 -0)
📝 crates/horizon-mods/src/content.rs (+37 -23)

📄 Description

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

What

A content pack loads faster: the first start builds its content root with fewer waits, and every start loads the mods' sprites and block models on all cores instead of one file at a time.

  • Content root build (mod_content::build, first start and after each game update). The 19 per-state tables (13 JSON, 6 NBT) are rewritten on up to three threads, largest first, instead of one after another; three because each holds a whole table as a tree (gameplay-facts.json's is over a gigabyte with ATM10's mods). A zip content mod's archive is now opened once for all its files (Content::reader) instead of once per file, which re-read the whole archive index each time (quadratic in the mod's file count).
  • Every start. hud::atlas_sprites (the mods' block and item textures for the HUD atlas) and ParsedModels::load (every models/**.json) list their files first, then decode and parse them on every core (par::par_map, a small work queue that returns results in input order). Sprites come out in the order the one-by-one loop produced, the first origin that loads still wins for each name, and the model walk now uses each entry's own file type (no stat per file; links are still followed).

The content root this builds is byte-identical to main's: diff -r of the two roots for the ATM10 pack (108,691 files) differs only in the stamp file, which records the executable.

Why

modpacks-12 brief, step 4: "the pack takes 27 s to load against 3.5 s without it. Profile and cut it (target under 10 s)". A sample profile of a warm start with ATM10's 42 data mods showed about 70 % of the main thread's samples in those two serial file loops (open and read of tens of thousands of small files); the first-start profile on the desktop (perf) showed the root build serial in its tables and the zip reopen.

Numbers

Mac mini (M4 Pro, 14 threads), ATM10's 42 data mods, --offscreen, render distance 12. The machine was shared with a CI build and other sessions (load average 30 to 60), so whole-start times swing by 2x between runs. The phases this changes were timed in-process (temporary log lines, not in this PR), alternating before/after:

median before after
block models parsed (hot cache, 5 pairs) 4.63 s 0.80 s
atlas sprites (hot, 5 pairs) 1.74 s 1.20 s
block models parsed (cold cache after purge, 3 pairs) 4.72 s 0.76 s
atlas sprites (cold, 3 pairs) 1.28 s 0.71 s
load assets (hot) 16.1 s 11.2 s
load assets (cold) 12.4 s 8.6 s

Whole warm starts when the machine was quieter ("resources loaded"): vanilla 1.3 to 2.5 s; the pack 7.3 to 8.6 s before and 6.6 to 8.2 s after. So the warm start is now under the 10 s target there. The first start (content root build) measured 33.4 / 36.7 / 57.8 s before and 25.0 / 35.1 / 45.0 s after on the busy Mac mini (medians 36.7 and 35.1 s, within the noise). It is dominated by writing the root's ~100k files. On the desktop the probe's root build measured 279 / 8.9 / 45 s before and 38 / 7.1 / 7.5 s after, under heavy I/O pressure from other harness runs. The zip fix only matters for packaged content mods; the launcher's ports are directories.

What's left, from the after profile: the per-state NBT tables read on every start (pack tables, facts, collisions, light: about 16 % of samples), a join on the projection thread (about 12 %), the stamp check, which stats every mod file on every start, and items/recipes loading. The root is also rebuilt whenever the executable changes (the stamp includes it), so every game update pays the first-start cost again.

How tested

On the desktop, origin/main e730dc14 + #1175 + #1176 + #1177 + this branch (467b450d):

cargo fmt --all -- --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings        ok, 0 errors (pipefail)
cargo build --release -p horizon-client --bin horizon-client ok
cargo test -p horizon-port-pack                              57 passed
cargo test -p horizon-mods                                   23 passed, 1 ignored
cargo test -p horizon-world --lib                            154 passed, 1 ignored
cargo test -p horizon-client --lib                           985 passed, 15 ignored (includes par::tests)
tools/parity.py --changed origin/main                        304 depend: 26 cached + 278 run, all pass (2 after fixing my shell's LD_LIBRARY_PATH, see the comment)

Rendering check on the Mac mini: the same world and view with a creative hotbar of mod items (Macaw's doors, roofs, fences and paths, Regions Unexplored, Mekanism Tools) screenshotted with main's build and this one: the hotbar rows differ in 15 pixels of 1280×720 (339 over the whole frame, the Nether's particles), so the HUD atlas holds the same sprites. The pack was also played through at seeds 1234 and 2 (structures, villages, the Nether) on the integration build.

Needs Ludovic

Nothing for this PR.

🤖 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/1191 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/mod-content-build` --- ### 📝 Commits (1) - [`8a03758`](https://github.com/horizon-rust/horizon/commit/8a03758c3a41c9d113864ddab3271bf523c6e8a6) Load time: build a pack's content root and load its sprites and models in parallel ### 📊 Changes **6 files changed** (+216 additions, -73 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/hud.rs` (+39 -20) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/mod_content.rs` (+63 -23) 📝 `crates/horizon-client/src/model_library.rs` (+22 -7) ➕ `crates/horizon-client/src/par.rs` (+54 -0) 📝 `crates/horizon-mods/src/content.rs` (+37 -23) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What A content pack loads faster: the first start builds its content root with fewer waits, and every start loads the mods' sprites and block models on all cores instead of one file at a time. - **Content root build** (`mod_content::build`, first start and after each game update). The 19 per-state tables (13 JSON, 6 NBT) are rewritten on up to three threads, largest first, instead of one after another; three because each holds a whole table as a tree (gameplay-facts.json's is over a gigabyte with ATM10's mods). A zip content mod's archive is now opened once for all its files (`Content::reader`) instead of once per file, which re-read the whole archive index each time (quadratic in the mod's file count). - **Every start.** `hud::atlas_sprites` (the mods' block and item textures for the HUD atlas) and `ParsedModels::load` (every `models/**.json`) list their files first, then decode and parse them on every core (`par::par_map`, a small work queue that returns results in input order). Sprites come out in the order the one-by-one loop produced, the first origin that loads still wins for each name, and the model walk now uses each entry's own file type (no stat per file; links are still followed). The content root this builds is byte-identical to main's: `diff -r` of the two roots for the ATM10 pack (108,691 files) differs only in the stamp file, which records the executable. ## Why modpacks-12 brief, step 4: "the pack takes 27 s to load against 3.5 s without it. Profile and cut it (target under 10 s)". A `sample` profile of a warm start with ATM10's 42 data mods showed about 70 % of the main thread's samples in those two serial file loops (`open` and `read` of tens of thousands of small files); the first-start profile on the desktop (perf) showed the root build serial in its tables and the zip reopen. ## Numbers Mac mini (M4 Pro, 14 threads), ATM10's 42 data mods, `--offscreen`, render distance 12. The machine was shared with a CI build and other sessions (load average 30 to 60), so whole-start times swing by 2x between runs. The phases this changes were timed in-process (temporary log lines, not in this PR), alternating before/after: | median | before | after | |---|---:|---:| | block models parsed (hot cache, 5 pairs) | 4.63 s | 0.80 s | | atlas sprites (hot, 5 pairs) | 1.74 s | 1.20 s | | block models parsed (cold cache after `purge`, 3 pairs) | 4.72 s | 0.76 s | | atlas sprites (cold, 3 pairs) | 1.28 s | 0.71 s | | `load assets` (hot) | 16.1 s | 11.2 s | | `load assets` (cold) | 12.4 s | 8.6 s | Whole warm starts when the machine was quieter ("resources loaded"): vanilla 1.3 to 2.5 s; the pack 7.3 to 8.6 s before and 6.6 to 8.2 s after. So the warm start is now under the 10 s target there. The first start (content root build) measured 33.4 / 36.7 / 57.8 s before and 25.0 / 35.1 / 45.0 s after on the busy Mac mini (medians 36.7 and 35.1 s, within the noise). It is dominated by writing the root's ~100k files. On the desktop the probe's root build measured 279 / 8.9 / 45 s before and 38 / 7.1 / 7.5 s after, under heavy I/O pressure from other harness runs. The zip fix only matters for packaged content mods; the launcher's ports are directories. What's left, from the after profile: the per-state NBT tables read on every start (pack tables, facts, collisions, light: about 16 % of samples), a join on the projection thread (about 12 %), the stamp check, which stats every mod file on every start, and items/recipes loading. The root is also rebuilt whenever the executable changes (the stamp includes it), so every game update pays the first-start cost again. ## How tested On the desktop, origin/main e730dc14 + #1175 + #1176 + #1177 + this branch (467b450d): ``` cargo fmt --all -- --check ok cargo clippy --workspace --all-targets -- -D warnings ok, 0 errors (pipefail) cargo build --release -p horizon-client --bin horizon-client ok cargo test -p horizon-port-pack 57 passed cargo test -p horizon-mods 23 passed, 1 ignored cargo test -p horizon-world --lib 154 passed, 1 ignored cargo test -p horizon-client --lib 985 passed, 15 ignored (includes par::tests) tools/parity.py --changed origin/main 304 depend: 26 cached + 278 run, all pass (2 after fixing my shell's LD_LIBRARY_PATH, see the comment) ``` Rendering check on the Mac mini: the same world and view with a creative hotbar of mod items (Macaw's doors, roofs, fences and paths, Regions Unexplored, Mekanism Tools) screenshotted with main's build and this one: the hotbar rows differ in 15 pixels of 1280×720 (339 over the whole frame, the Nether's particles), so the HUD atlas holds the same sprites. The pack was also played through at seeds 1234 and 2 (structures, villages, the Nether) on the integration build. ## Needs Ludovic Nothing for this PR. 🤖 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 04:09:18 +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#3407
No description provided.