[PR #4156] [MERGED] Far terrain: decorated chunks kept on disk, read again next session #5447

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4156
Author: @spidercraft
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @rdbtCVS

Base: main ← Head: far-terrain-cache


📝 Commits (2)

  • 2e321e3 Far terrain: decorated chunks kept on disk, read again next session
  • 8922550 Far terrain cache: a chunk cached already is not written again

📊 Changes

3 files changed (+388 additions, -2 deletions)

View changed files

📝 crates/horizon-client-render/src/lod.rs (+1 -0)
➕ crates/horizon-client-render/src/lod/cache.rs (+356 -0)
📝 crates/horizon-client/src/save.rs (+31 -2)

📄 Description

🤖 Opened by Claude Code.

Far terrain, part 1 of 4. This PR: decorated far chunks kept on disk. Next: #4157 (speed and loading order), #4158 (light and water), #4159 (fades). Each later part contains the ones before it: merge in order, and review each PR's own commit.

What and why

Far terrain decorates the chunks of its nearest ring with the world's own generator (real trees and structures, vanillagen/lod.rs), but kept them in memory only, 1024 at most, so every session generated them all again.

They now go to dimensions/<dim>/data/horizon_far_terrain/, one append-only file per 32×32 region (lod/cache.rs, about 6 KB a chunk, deflated), and a detail request reads them back before asking the generator (SavedLodSampler, save.rs).

  • Saved chunks still take precedence: a chunk the player visited never shows its cached, generated build.
  • A file written by another build (its commit, or a local build's executable time), block registry, biome count or format is cleared on first use; a torn last record (a crash mid-write) is cut off.
  • Only detail requests read the cache. Reading it for every cell of the coarse tiles' sampling slowed their sampling more than it saved (measured).
  • No size cap: about 75 MB for the whole detail ring around one spot.

Measured

Rejoining a world at LOD Distance 512 (seed 1234, render distance 12): 343k refined far cells after 45 s with the cache, 244k without (the same session, its cache folder deleted); frame rate unchanged.

Tests

lod::cache tests (reopen, a chunk written twice, a torn record, another build's file, damaged records), and save::tests::saved_far_surface_reads_builds_and_water_without_gameplay_chunks now checks that saved builds are not cached as generated and that a cached chunk answers a later request.

pr_ready on the top of this stack (#4159, which contains this PR):

pr_ready (tools/pr_ready.py --quick on SpiderPC, against origin/main at 25f9cd3a9, 2 min 15 s)

Check Result
Scope ⚠️ 12 files, +1175 −295; 1470 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (26 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 0 s)
tests: horizon-client, horizon-client-render ✅ 1527 passed (43 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root 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 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/4156 **Author:** [@spidercraft](https://github.com/spidercraft) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `far-terrain-cache` --- ### 📝 Commits (2) - [`2e321e3`](https://github.com/horizon-rust/horizon/commit/2e321e385a769bcaaff350c4fb194c89eefbfd1a) Far terrain: decorated chunks kept on disk, read again next session - [`8922550`](https://github.com/horizon-rust/horizon/commit/8922550fdf258558b0a03609772168ce8c5fe6d6) Far terrain cache: a chunk cached already is not written again ### 📊 Changes **3 files changed** (+388 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/lod.rs` (+1 -0) ➕ `crates/horizon-client-render/src/lod/cache.rs` (+356 -0) 📝 `crates/horizon-client/src/save.rs` (+31 -2) </details> ### 📄 Description > 🤖 Opened by Claude Code. **Far terrain, part 1 of 4.** This PR: decorated far chunks kept on disk. Next: #4157 (speed and loading order), #4158 (light and water), #4159 (fades). Each later part contains the ones before it: merge in order, and review each PR's own commit. ## What and why Far terrain decorates the chunks of its nearest ring with the world's own generator (real trees and structures, `vanillagen/lod.rs`), but kept them in memory only, 1024 at most, so every session generated them all again. They now go to `dimensions/<dim>/data/horizon_far_terrain/`, one append-only file per 32×32 region (`lod/cache.rs`, about 6 KB a chunk, deflated), and a detail request reads them back before asking the generator (`SavedLodSampler`, `save.rs`). - Saved chunks still take precedence: a chunk the player visited never shows its cached, generated build. - A file written by another build (its commit, or a local build's executable time), block registry, biome count or format is cleared on first use; a torn last record (a crash mid-write) is cut off. - Only detail requests read the cache. Reading it for every cell of the coarse tiles' sampling slowed their sampling more than it saved (measured). - No size cap: about 75 MB for the whole detail ring around one spot. ## Measured Rejoining a world at LOD Distance 512 (seed 1234, render distance 12): **343k refined far cells after 45 s with the cache, 244k without** (the same session, its cache folder deleted); frame rate unchanged. ## Tests `lod::cache` tests (reopen, a chunk written twice, a torn record, another build's file, damaged records), and `save::tests::saved_far_surface_reads_builds_and_water_without_gameplay_chunks` now checks that saved builds are not cached as generated and that a cached chunk answers a later request. pr_ready on the top of this stack (#4159, which contains this PR): **pr_ready** (`tools/pr_ready.py --quick` on SpiderPC, against origin/main at 25f9cd3a9, 2 min 15 s) | Check | Result | | --- | --- | | Scope | ⚠️ 12 files, +1175 −295; 1470 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (26 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 0 s) | | tests: horizon-client, horizon-client-render | ✅ 1527 passed (43 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root 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 [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 05:12:39 +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#5447
No description provided.