[PR #6893] [MERGED] Prepared data file: recipes and loot tables read from one file (horizon-data.bin) #7175

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6893
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/prepared-data-file


📝 Commits (1)

  • 4935b69 Prepared data file: the recipe and loot folders read from one file

📊 Changes

8 files changed (+579 additions, -12 deletions)

View changed files

📝 crates/horizon-client-render/src/packs.rs (+2 -1)
📝 crates/horizon-client/src/game.rs (+33 -0)
📝 crates/horizon-client/src/mod_content.rs (+5 -0)
📝 crates/horizon-core/src/lib.rs (+1 -0)
➕ crates/horizon-core/src/prepared_files.rs (+460 -0)
📝 crates/horizon-world/src/json_folder.rs (+69 -9)
📝 tests/test_lab.py (+2 -1)
📝 tools/check_public_tree.py (+7 -1)

📄 Description

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

Part of #1961 (Windows Defender scans every file the start opens, ~1 ms each after a signature update: 77–92 s first starts); first step of #4267's horizon-data.bin.

What

  • horizon-core::prepared_files: the prepared folder's data/ and assets/ files (sounds aside) in one file, read through one open handle with positional reads (no mmap, no unsafe, no lock on the file under Windows).
    • Layout (little-endian, 8-aligned): magic HZDATA\0\0, version; the root's canonical path and the bytes of horizon-resources.json it was written from; sorted entries (name in a pool, offset, length); the files' bytes.
    • Used only for the root it was written for and the preparation it was written from, and never through a symlink. Anything else (missing, another root's copy, re-prepared, cut short, HORIZON_NO_DATA_FILE=1) reads the folders as today.
    • Written into a temporary file, then renamed into place.
  • Who writes it: the game, for the vanilla root, on an idle-priority thread once the start is done (rest-ready), when there is none it can use. That start has just read the files, so they are in the disk cache. Existing installs gain at their second start, with no re-prepare.
  • First reader: json_folder, so the recipes and the loot tables, predicates and modifiers. The other folders (textures, tags, models, advancements, items, blockstates) move in the next PRs, measured the same way.
  • The resource-pack mirror (packs::build_overlay) and the content-mod root (mod_content::build) don't link it: it describes vanilla's root, and the content root would have copied 18 MB where it can't link. check_public_tree.py rejects the name; like the folders it re-encodes, it is never committed or published.

A/B (playhorizon, llvmpipe; a copy of the prepared root, page cache dropped before each cold run)

Base = main 401bc1605, new = bbf19eb1b.

base new
files opened under the prepared root, --world start → in world 40,282 27,905 (−31%)
… in data/minecraft/recipe 8,174 2
… in data/minecraft/loot_table 1,643 140
horizon-data.bin — 18.4 MB, written 7 s after the first start
cold start → title (ms), 3 alternated runs 3702 / 3440 / 4467 4331 / 4128 / 3787
cold start → first world frame (ms) 12013 / 11933 / 14153 11442 / 7977 / 8352

The box was at load 17–19 (other build slots), and its SSD shows no I/O signal at this size, so the times are noise. The change is in the file count, which is what costs under Defender (~1 ms each) and on a hard disk (a seek each): ~12,400 fewer opens at every start. The next PRs take the remaining 27,900 (textures 9.7k, tags 6.7k, models 4.2k…).

Tests

  • prepared_files: reads and lists back what the folders hold (sounds and top-level tables left to the folder; recipe isn't a prefix of recipes). A file from another preparation, cut short, copied or linked into another root isn't used. find resolves a folder to its root.
  • json_folder: under a prepared root with a file, the folder reads from it, with the folder's own names, order and paths.
  • check_public_tree: the name is rejected.

🤖 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/6893 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/prepared-data-file` --- ### 📝 Commits (1) - [`4935b69`](https://github.com/horizon-rust/horizon/commit/4935b692c35322d3a380006f39c0bd280c6973a7) Prepared data file: the recipe and loot folders read from one file ### 📊 Changes **8 files changed** (+579 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/packs.rs` (+2 -1) 📝 `crates/horizon-client/src/game.rs` (+33 -0) 📝 `crates/horizon-client/src/mod_content.rs` (+5 -0) 📝 `crates/horizon-core/src/lib.rs` (+1 -0) ➕ `crates/horizon-core/src/prepared_files.rs` (+460 -0) 📝 `crates/horizon-world/src/json_folder.rs` (+69 -9) 📝 `tests/test_lab.py` (+2 -1) 📝 `tools/check_public_tree.py` (+7 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of #1961 (Windows Defender scans every file the start opens, ~1 ms each after a signature update: 77–92 s first starts); first step of #4267's `horizon-data.bin`. ## What - **`horizon-core::prepared_files`**: the prepared folder's `data/` and `assets/` files (sounds aside) in one file, read through one open handle with positional reads (no `mmap`, no `unsafe`, no lock on the file under Windows). - Layout (little-endian, 8-aligned): magic `HZDATA\0\0`, version; the root's canonical path and the bytes of `horizon-resources.json` it was written from; sorted entries (name in a pool, offset, length); the files' bytes. - Used only for the root it was written for and the preparation it was written from, and never through a symlink. Anything else (missing, another root's copy, re-prepared, cut short, `HORIZON_NO_DATA_FILE=1`) reads the folders as today. - Written into a temporary file, then renamed into place. - **Who writes it:** the game, for the vanilla root, on an idle-priority thread once the start is done (`rest-ready`), when there is none it can use. That start has just read the files, so they are in the disk cache. Existing installs gain at their second start, with no re-prepare. - **First reader:** `json_folder`, so the recipes and the loot tables, predicates and modifiers. The other folders (textures, tags, models, advancements, items, blockstates) move in the next PRs, measured the same way. - The resource-pack mirror (`packs::build_overlay`) and the content-mod root (`mod_content::build`) don't link it: it describes vanilla's root, and the content root would have copied 18 MB where it can't link. `check_public_tree.py` rejects the name; like the folders it re-encodes, it is never committed or published. ## A/B (playhorizon, llvmpipe; a copy of the prepared root, page cache dropped before each cold run) Base = main 401bc1605, new = bbf19eb1b. | | base | new | |---|---:|---:| | files opened under the prepared root, `--world` start → in world | 40,282 | **27,905** (−31%) | | … in `data/minecraft/recipe` | 8,174 | **2** | | … in `data/minecraft/loot_table` | 1,643 | **140** | | `horizon-data.bin` | — | 18.4 MB, written 7 s after the first start | | cold start → title (ms), 3 alternated runs | 3702 / 3440 / 4467 | 4331 / 4128 / 3787 | | cold start → first world frame (ms) | 12013 / 11933 / 14153 | 11442 / 7977 / 8352 | The box was at load 17–19 (other build slots), and its SSD shows no I/O signal at this size, so the times are noise. The change is in the file count, which is what costs under Defender (~1 ms each) and on a hard disk (a seek each): ~12,400 fewer opens at every start. The next PRs take the remaining 27,900 (textures 9.7k, tags 6.7k, models 4.2k…). ## Tests - `prepared_files`: reads and lists back what the folders hold (sounds and top-level tables left to the folder; `recipe` isn't a prefix of `recipes`). A file from another preparation, cut short, copied or linked into another root isn't used. `find` resolves a folder to its root. - `json_folder`: under a prepared root with a file, the folder reads from it, with the folder's own names, order and paths. - `check_public_tree`: the name is rejected. 🤖 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 06:35:15 +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#7175
No description provided.