[GH-ISSUE #4458] Optimize terrain fill, aquifer cell caching, and 48-bit positional seeding #1335

Closed
opened 2026-11-02 15:46:07 +07:00 by bsakaguchi · 2 comments
Owner

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

🤖 Filed by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally.

Description

World generation and terrain stage generation spend significant compute on repeated allocations, redundant coordinate evaluations, and uncached traversals:

  1. fill_noise allocates a fresh 393 KB (98,304 floats) density buffer for every chunk pass, and evaluates 98,304 redundant volume.index([x, y, z]) calls in the fill loop.
  2. In the top-down terrain fill sweep, heightmaps (WorldSurfaceWg and OceanFloorWg) are continually probed and evaluated for every block down the column (~31,700 block checks per chunk), even after both heightmaps have already been set at the column surface.
  3. NoiseBasedAquifer::compute_substance recomputes the horizontal squared distance \Delta x^2 + \Delta z^2 on every $ coordinate for each of the 12 neighborhood cells, despite $, $, and the grid cell anchors being invariant across the vertical column slab.
  4. LegacyPositionalRandom::at(pos) performs full 48-bit multiplicative linear congruential seeding on every call rather than precomputing the constant base state.
  5. apply_carving_mask unconditionally compiles material conditions and constructs temporary density volumes even when the carving mask is completely empty.

Proposed Solution

  1. Provide thread-local scratch buffer reuse and hoisted column slices for fill_noise.
  2. Add monotonic top-down heightmap termination in fill_noise to bypass subterranean heightmap queries once settled.
  3. Cache horizontal distances and cell coordinates in NoiseBasedAquifer across vertical cell slabs.
  4. Precompute the 48-bit masked seed base in LegacyPositionalRandom.
  5. Early-return from apply_carving_mask when mask.is_empty().
Originally created by @elythepreciouscat on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4458 > 🤖 Filed by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally. ### Description World generation and terrain stage generation spend significant compute on repeated allocations, redundant coordinate evaluations, and uncached traversals: 1. `fill_noise` allocates a fresh 393 KB (98,304 floats) density buffer for every chunk pass, and evaluates 98,304 redundant `volume.index([x, y, z])` calls in the fill loop. 2. In the top-down terrain fill sweep, heightmaps (`WorldSurfaceWg` and `OceanFloorWg`) are continually probed and evaluated for every block down the column (~31,700 block checks per chunk), even after both heightmaps have already been set at the column surface. 3. `NoiseBasedAquifer::compute_substance` recomputes the horizontal squared distance $\Delta x^2 + \Delta z^2$ on every $ coordinate for each of the 12 neighborhood cells, despite **$**, **$**, and the grid cell anchors being invariant across the vertical column slab. 4. `LegacyPositionalRandom::at(pos)` performs full 48-bit multiplicative linear congruential seeding on every call rather than precomputing the constant base state. 5. `apply_carving_mask` unconditionally compiles material conditions and constructs temporary density volumes even when the carving mask is completely empty. ### Proposed Solution 1. Provide thread-local scratch buffer reuse and hoisted column slices for `fill_noise`. 2. Add monotonic top-down heightmap termination in `fill_noise` to bypass subterranean heightmap queries once settled. 3. Cache horizontal distances and cell coordinates in `NoiseBasedAquifer` across vertical cell slabs. 4. Precompute the 48-bit masked seed base in `LegacyPositionalRandom`. 5. Early-return from `apply_carving_mask` when `mask.is_empty()`.
Author
Owner

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

🤖 Agent: /claim

<!-- gh-comment-id:6525872862 --> @elythepreciouscat commented on GitHub (Oct 30, 2026): 🤖 Agent: /claim
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

🤖 Claims: refused, You hold 5 open issues: finish or /unclaim one first. (asked by @elythepreciouscat)

<!-- gh-comment-id:6525898362 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): 🤖 Claims: refused, You hold 5 open issues: finish or `/unclaim` one first. (asked by @elythepreciouscat)
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#1335
No description provided.