[PR #7401] [CLOSED] Worldgen data: snapshot the parsed bundles #7579

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7401
Author: @socksprox
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: perf/worldgen-data-snapshot


📝 Commits (2)

  • 23c19e2 Worldgen data: snapshot the parsed bundles, keyed like the behaviour cache
  • 8d44618 worldgen_load_profile: time GeneratorData::load like behaviour_load_profile

📊 Changes

8 files changed (+679 additions, -57 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+3 -0)
➕ crates/horizon-world/examples/worldgen_load_profile.rs (+35 -0)
📝 crates/horizon-world/src/level/data/cache.rs (+1 -21)
📝 crates/horizon-world/src/registry.rs (+33 -0)
📝 crates/horizon-world/src/worldgen.rs (+1 -0)
📝 crates/horizon-world/src/worldgen/generator.rs (+142 -35)
➕ crates/horizon-world/src/worldgen/generator_cache.rs (+461 -0)
📝 docs/world-generation.md (+3 -1)

📄 Description

🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally.

What and why

Fixes #7400.

GeneratorData::load re-parses every worldgen/*.json bundle file with serde_json::from_str on every start — the biggest cost of world loading. This adds a worldgen-v1.bin snapshot beside behaviours-v2.bin in the game's .horizon-cache, following the level/data/cache.rs pattern:

  • worldgen/generator_cache.rs: a disposable snapshot of the parsed bundles (stem → id → JSON text), so a cache hit is a postcard decode instead of a JSON parse. The fingerprint keys the running executable, the block registry and every file under the worldgen/ dir (structure/ excepted — its templates load lazily after this and always serve the current file). Corrupt payloads, version mismatches and changed files fall back to the files.
  • Bundles is the load's bundle source: Disk parses and records for the snapshot; Snapshot serves recorded bundles and falls back to the directory for anything it doesn't hold. Data packs (WorldgenOverrides) join the bundles after restore, so every world's load shares one snapshot of the resource bundle and the fingerprint needn't cover pack files.
  • Everything else the load reads (block_flags.json, biome_parameters/, the blocks/ tables, structure-blocks.json, Behaviours's own files) still comes from the directory, which the fingerprint already covered; Behaviours keeps its own snapshot.
  • registry::cache_key factors the registry-hashing half of the fingerprint out of level/data/cache.rs so both caches share it.
  • Wired with GeneratorData::set_cache_dir beside Behaviours::set_cache_dir; without a cache folder (tests, tools, servers) loads read the files exactly as before.

Not taken: the optional typed-struct deserialization for lower peak memory (the Value parses in StateTransforms/quantize_parameter_report stay), and the ≤4 source_json decoration-cache keys (bounded, small).

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only plumbing; no vanilla behavior changes. Verification: the snapshot replays identical inputs into an identical resolve, so generation is unchanged — a new test resolves real resources through both paths and generate_protos two chunks byte-identically (sections, heightmaps, post-processing, carried ticks), and the worldgen parity harnesses cover the resolve itself.

Other projects' code

none

Self-check

python3 tools/pr_ready.py --quick (MacBookPro, against origin/main at fdd290b99, 2 min 14 s)

Check Result
Scope ⚠️ 7 files, +644 −57; 697 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (1 min 17 s)
rustfmt ✅ (12 s)
clippy ✅ (30 s)
tests: horizon-client, horizon-world ✅ 1102 passed (12 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Devin


🔄 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/7401 **Author:** [@socksprox](https://github.com/socksprox) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/worldgen-data-snapshot` --- ### 📝 Commits (2) - [`23c19e2`](https://github.com/horizon-rust/horizon/commit/23c19e2d8d38ea0c5d13d27b500487550dd0bce5) Worldgen data: snapshot the parsed bundles, keyed like the behaviour cache - [`8d44618`](https://github.com/horizon-rust/horizon/commit/8d446189bcaf65aacee5324618e7c716ebf78899) worldgen_load_profile: time GeneratorData::load like behaviour_load_profile ### 📊 Changes **8 files changed** (+679 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+3 -0) ➕ `crates/horizon-world/examples/worldgen_load_profile.rs` (+35 -0) 📝 `crates/horizon-world/src/level/data/cache.rs` (+1 -21) 📝 `crates/horizon-world/src/registry.rs` (+33 -0) 📝 `crates/horizon-world/src/worldgen.rs` (+1 -0) 📝 `crates/horizon-world/src/worldgen/generator.rs` (+142 -35) ➕ `crates/horizon-world/src/worldgen/generator_cache.rs` (+461 -0) 📝 `docs/world-generation.md` (+3 -1) </details> ### 📄 Description > 🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally. ## What and why Fixes #7400. `GeneratorData::load` re-parses every `worldgen/*.json` bundle file with `serde_json::from_str` on every start — the biggest cost of world loading. This adds a `worldgen-v1.bin` snapshot beside `behaviours-v2.bin` in the game's `.horizon-cache`, following the `level/data/cache.rs` pattern: - `worldgen/generator_cache.rs`: a disposable snapshot of the parsed bundles (`stem → id → JSON text`), so a cache hit is a postcard decode instead of a JSON parse. The fingerprint keys the running executable, the block registry and every file under the `worldgen/` dir (`structure/` excepted — its templates load lazily after this and always serve the current file). Corrupt payloads, version mismatches and changed files fall back to the files. - `Bundles` is the load's bundle source: `Disk` parses and records for the snapshot; `Snapshot` serves recorded bundles and falls back to the directory for anything it doesn't hold. Data packs (`WorldgenOverrides`) join the bundles *after* restore, so every world's load shares one snapshot of the resource bundle and the fingerprint needn't cover pack files. - Everything else the load reads (`block_flags.json`, `biome_parameters/`, the `blocks/` tables, `structure-blocks.json`, `Behaviours`'s own files) still comes from the directory, which the fingerprint already covered; `Behaviours` keeps its own snapshot. - `registry::cache_key` factors the registry-hashing half of the fingerprint out of `level/data/cache.rs` so both caches share it. - Wired with `GeneratorData::set_cache_dir` beside `Behaviours::set_cache_dir`; without a cache folder (tests, tools, servers) loads read the files exactly as before. Not taken: the optional typed-struct deserialization for lower peak memory (the `Value` parses in `StateTransforms`/`quantize_parameter_report` stay), and the ≤4 `source_json` decoration-cache keys (bounded, small). ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only plumbing; no vanilla behavior changes. Verification: the snapshot replays identical inputs into an identical resolve, so generation is unchanged — a new test resolves real resources through both paths and `generate_proto`s two chunks byte-identically (sections, heightmaps, post-processing, carried ticks), and the worldgen parity harnesses cover the resolve itself. ## Other projects' code none ## Self-check `python3 tools/pr_ready.py --quick` (MacBookPro, against origin/main at fdd290b99, 2 min 14 s) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +644 −57; 697 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (1 min 17 s) | | rustfmt | ✅ (12 s) | | clippy | ✅ (30 s) | | tests: horizon-client, horizon-world | ✅ 1102 passed (12 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Devin](https://devin.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:11 +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#7579
No description provided.