[GH-ISSUE #4267] Server-next W5 design: prepared data as one mmapped file written by horizon-prepare #1253

Open
opened 2026-11-02 15:45:26 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ludovic111 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4267

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

Design for discussion. No code until it's agreed. Part of the server plan #3989 (idle memory; Pumpkin idles at 32 MB).

Why

After W4 (#4232, #4242, #4245, #4257), a dedicated server should idle at about 250 MB RSS on Linux. The combined heap profile (234 MB tracked on macOS, 37 MB of it thread stacks) is mostly vanilla data parsed into heap structures at startup:

Data Heap
block registry states (names, property maps) 31 MB
worldgen bindings and caches ~36 MB
items, with a copy of the loot tables 15 MB
block facts and gameplay projection 12 MB
level data shapes 10 MB
LAN sync packets 9.5 MB
advancements 8.4 MB
loot 8 MB

Trimming (the W4 list) reaches about 175 MB. Below that, the data has to leave the heap.

The rule this must keep

Nothing of Mojang's is shipped: no tables generated into our binaries or releases. So the data file is written by horizon-prepare, from the owner's own copy, in the prepared folder (.local/horizon-client/26.3/ or the launcher's install). It sits next to the JSON and NBT files it re-encodes, and like them is never committed and never published (check_public_tree.py gets the new name).

Format: horizon-data.bin

  • Header:
    • magic HZDATA\0\0, format version;
    • DATA_VERSION;
    • the horizon-resources.json hashes (client, server, exporter);
    • a SHA-256 of every source file it was built from;
    • a section table: id, offset, length, record size; every offset 8-aligned.
  • Sections: flat little-endian arrays of fixed-size records, plus one string pool. Strings are interned once (block and property names, ids, tags), and records hold u32 offsets into the pool. There are no pointers, so the file maps as is.
  • Reading: the game opens it with memmap2 (already in Cargo.lock) and reads records through bytemuck/zerocopy views (both already in the tree). Every section's bounds and counts are checked once at open. Any mismatch (hashes, version, size, a bad offset) falls back to today's loaders, as level/data/cache.rs already does for its behaviour snapshot. Sharing: horizon-prepare writes a temp file and renames it into place, so a running server keeps its old mapping.
  • Memory: the pages are file-backed, shared between processes (two servers, or the game and its server thread), and paged in on demand. An idle server only touches what it reads.

What moves first (each its own PR, A/B'd like W4)

Order updated 2026-10-30 (orchestrator): loot tables first, block facts later without breaking their API.

  1. Format, writer, reader, horizon-prepare --verify-data, and loot tables as the first section (~7 MB): the exported JSON bytes per id, parsed on first use, so most are never parsed on an idle server. Conditions:
    • lazy parsing moves a bad table's error from startup to first use, so --verify-data and a unit test parse every table; the fallback to today's loader stays when the file is missing or stale;
    • data-pack and content-mod loot overrides still win over the mapped base, with a test that shows it;
    • the PR reports the worst single-table parse time (a first use on the tick thread must not show as a spike).
  2. Item components, advancements, recipes as raw JSON slices (~20 MB), the same way.
  3. Block facts (W4-bis): shrink StateFacts with shared indexes in heap first, keeping its API; map them later only if it still pays.
  4. Shape tables (collision, support, occlusion, level data shapes, ~10 MB): boxes and coordinates as arrays. VoxelShape keeps its identity semantics through a per-shape index.
  5. LAN sync packets for the base data (no world data packs): written as finished packet bytes, sent straight from the map at join.
  6. Block registry states (31 MB). This is the parked BlockState interning: it needs registry.state() to return a borrowed view instead of &BlockState with Strings. It goes last, when the contributor queue allows a cross-cutting diff.

Expected RSS

  • Steps 1–5 take roughly 60 MB off the heap: about 115–140 MB idle once the W4 list lands.
  • Step 6 takes about 20 MB more.
  • Below about 100 MB, what remains is worldgen state (bindings for three dimensions), touched code pages of a 67 MB binary, and allocator overhead.
  • 32 MB would also need lazy dimensions and a smaller binary. I'll measure, not promise.

Staying vanilla-exact

  • The file is a lossless re-encoding of the same exported files; nothing is computed differently.
  • --verify-data and a unit test decode every section and compare it, record by record, with today's loaders on the same root.
  • The parity harnesses don't change and keep running against real jars.
  • Data-pack and content-mod overlays stay in heap and layer over the mapped base as they do now (only changed entries).
  • A content root built by mod_content::build either gets its own file or uses the loaders.

Effect on the client

  • Single player runs the same tables (window plus server thread), so it gains the same, plus faster startup: no 9.7 MB facts.json parse, no loot and advancement parsing.
  • The client's render data (models, sprites) is out of scope.
  • horizon-prepare takes a few seconds longer.
  • The launcher's update and repair paths treat the file like any other prepared file: rebuilt when its hashes don't match.

Open questions

  1. Should the file live in the prepared folder (shared by worktrees and installs), or in the game's cache folder like behaviours-v2.bin? I propose the prepared folder: it is derived only from the prepared files.
  2. Write it in horizon-prepare only, or also lazily from the game on first start when it's missing? I propose both, with the same writer, so existing installs gain without re-preparing.
Originally created by @ludovic111 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4267 > 🤖 Filed by Ludovic's AI agent (Claude), not by Ludovic himself. Design for discussion. No code until it's agreed. Part of the server plan #3989 (idle memory; Pumpkin idles at 32 MB). ## Why After W4 (#4232, #4242, #4245, #4257), a dedicated server should idle at about 250 MB RSS on Linux. The combined heap profile (234 MB tracked on macOS, 37 MB of it thread stacks) is mostly vanilla data parsed into heap structures at startup: | Data | Heap | |---|---| | block registry states (names, property maps) | 31 MB | | worldgen bindings and caches | ~36 MB | | items, with a copy of the loot tables | 15 MB | | block facts and gameplay projection | 12 MB | | level data shapes | 10 MB | | LAN sync packets | 9.5 MB | | advancements | 8.4 MB | | loot | 8 MB | Trimming (the W4 list) reaches about 175 MB. Below that, the data has to leave the heap. ## The rule this must keep Nothing of Mojang's is shipped: no tables generated into our binaries or releases. So the data file is written by **`horizon-prepare`, from the owner's own copy**, in the prepared folder (`.local/horizon-client/26.3/` or the launcher's install). It sits next to the JSON and NBT files it re-encodes, and like them is never committed and never published (`check_public_tree.py` gets the new name). ## Format: `horizon-data.bin` - **Header:** - magic `HZDATA\0\0`, format version; - `DATA_VERSION`; - the `horizon-resources.json` hashes (client, server, exporter); - a SHA-256 of every source file it was built from; - a section table: id, offset, length, record size; every offset 8-aligned. - **Sections:** flat little-endian arrays of fixed-size records, plus one string pool. Strings are interned once (block and property names, ids, tags), and records hold `u32` offsets into the pool. There are no pointers, so the file maps as is. - **Reading:** the game opens it with `memmap2` (already in `Cargo.lock`) and reads records through `bytemuck`/`zerocopy` views (both already in the tree). Every section's bounds and counts are checked once at open. Any mismatch (hashes, version, size, a bad offset) falls back to today's loaders, as `level/data/cache.rs` already does for its behaviour snapshot. Sharing: `horizon-prepare` writes a temp file and renames it into place, so a running server keeps its old mapping. - **Memory:** the pages are file-backed, shared between processes (two servers, or the game and its server thread), and paged in on demand. An idle server only touches what it reads. ## What moves first (each its own PR, A/B'd like W4) _Order updated 2026-10-30 (orchestrator): loot tables first, block facts later without breaking their API._ 1. **Format, writer, reader, `horizon-prepare --verify-data`, and loot tables as the first section** (~7 MB): the exported JSON bytes per id, parsed on first use, so most are never parsed on an idle server. Conditions: - lazy parsing moves a bad table's error from startup to first use, so `--verify-data` and a unit test parse every table; the fallback to today's loader stays when the file is missing or stale; - data-pack and content-mod loot overrides still win over the mapped base, with a test that shows it; - the PR reports the worst single-table parse time (a first use on the tick thread must not show as a spike). 2. **Item components, advancements, recipes as raw JSON slices** (~20 MB), the same way. 3. **Block facts (W4-bis):** shrink `StateFacts` with shared indexes in heap first, keeping its API; map them later only if it still pays. 4. **Shape tables** (collision, support, occlusion, level data shapes, ~10 MB): boxes and coordinates as arrays. `VoxelShape` keeps its identity semantics through a per-shape index. 5. **LAN sync packets** for the base data (no world data packs): written as finished packet bytes, sent straight from the map at join. 6. **Block registry states** (31 MB). This is the parked `BlockState` interning: it needs `registry.state()` to return a borrowed view instead of `&BlockState` with `String`s. It goes last, when the contributor queue allows a cross-cutting diff. ## Expected RSS - Steps 1–5 take roughly 60 MB off the heap: about 115–140 MB idle once the W4 list lands. - Step 6 takes about 20 MB more. - Below about 100 MB, what remains is worldgen state (bindings for three dimensions), touched code pages of a 67 MB binary, and allocator overhead. - 32 MB would also need lazy dimensions and a smaller binary. I'll measure, not promise. ## Staying vanilla-exact - The file is a lossless re-encoding of the same exported files; nothing is computed differently. - `--verify-data` and a unit test decode every section and compare it, record by record, with today's loaders on the same root. - The parity harnesses don't change and keep running against real jars. - Data-pack and content-mod overlays stay in heap and layer over the mapped base as they do now (only changed entries). - A content root built by `mod_content::build` either gets its own file or uses the loaders. ## Effect on the client - Single player runs the same tables (window plus server thread), so it gains the same, plus faster startup: no 9.7 MB `facts.json` parse, no loot and advancement parsing. - The client's render data (models, sprites) is out of scope. - `horizon-prepare` takes a few seconds longer. - The launcher's update and repair paths treat the file like any other prepared file: rebuilt when its hashes don't match. ## Open questions 1. Should the file live in the prepared folder (shared by worktrees and installs), or in the game's cache folder like `behaviours-v2.bin`? I propose the prepared folder: it is derived only from the prepared files. 2. Write it in `horizon-prepare` only, or also lazily from the game on first start when it's missing? I propose both, with the same writer, so existing installs gain without re-preparing.
Author
Owner

@ludovic111 commented on GitHub (Oct 30, 2026):

🤖 Agent: step list reordered per the maintainer's orchestrator: loot tables are the first section (with the three conditions now listed under step 1), block facts move to a W4-bis heap shrink that keeps the StateFacts API.

<!-- gh-comment-id:6518461247 --> @ludovic111 commented on GitHub (Oct 30, 2026): 🤖 Agent: step list reordered per the maintainer's orchestrator: loot tables are the first section (with the three conditions now listed under step 1), block facts move to a W4-bis heap shrink that keeps the `StateFacts` API.
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#1253
No description provided.