[PR #6711] [MERGED] Worldgen: skip heightmap updates for writes under the surface #7046

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

📋 Pull Request Information

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

Base: main ← Head: perf/worldgen-heightmap-fast


📝 Commits (1)

  • 340dfd1 Worldgen writes deep under a heightmap's surface skip its update

📊 Changes

3 files changed (+76 additions, -4 deletions)

View changed files

📝 crates/horizon-world/src/heightmap.rs (+12 -0)
📝 crates/horizon-world/src/worldgen/terrain.rs (+11 -4)
📝 crates/horizon-world/tests/feature_region.rs (+53 -0)

📄 Description

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

World generation writes every block of a proto chunk through set_block_worldgen, which updates each of the
chunk's heightmaps per write. For a write two or more blocks under a heightmap's first available y, vanilla's
Heightmap.update returns at once, but our path still went through update_heightmap for every map: a packed read,
the chunk check and several Result branches, on writes that are mostly 50-300 blocks under the surface (noise fill,
stone to deepslate, ore veins, carvers).

Heightmap::below_update answers that case with one packed read; set_block_worldgen then only checks the state as
before and skips the update. The other cases still call update_heightmap unchanged, so the maps are the same.

Test: feature_region::worldgen_writes_keep_heightmaps_as_updating_each_write primes the maps of a Biomes-stage and
a Terrain-stage chunk, then makes 20 000 random writes (mostly air/stone/water around the surface and under it)
through set_block_worldgen and, on a copy, through set_block_raw + update_heightmap per map; heightmaps and
blocks must be equal.

Numbers

playhorizon (Linux, 8 vCPU, taskset 0-3, load ~40), chunkgen_bench --size 24 --threads 1 (576 proto chunks),
4 alternating A/B pairs:

main this PR
CPU per proto chunk 10.65 ms 10.35 ms (-2.8%, faster in 4 of 4 pairs)

Generation output is unchanged (harnesses below). Not measured: world entry in perf_bench and many-core scaling
(the fleet machines were loaded 20-45 all night; CPU time per chunk is the reliable number then).

Parity (tools/parity.py on playhorizon at 340dfd1d3e, the generation and light harnesses of the 383 it selects; CI runs the rest):
10 passed, 0 failed in 41.1 min: chunk_generation, decorated_region, decoration, heightmap, light, material_surface, retrogen_chunk, server_world_gen, worldgen, worldgen_random (chunk_generation passed on its retry without reused oracle results).

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 06f842dc3, 21 min 42 s)

Check Result
Scope ✅ 3 files, +76 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 595 passed (1 min 18 s)
rustfmt ✅ (15 s)
clippy ✅ (9 min 1 s)
tests: horizon-world ✅ 376 passed (10 min 21 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 ➖ 202 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, attribute_updates, audio_attributes, auto_jump, bamboo, basic_feature, biome_chunk, biome_generation, biome_placement and 190 more
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/6711 **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/worldgen-heightmap-fast` --- ### 📝 Commits (1) - [`340dfd1`](https://github.com/horizon-rust/horizon/commit/340dfd1d3e97ffec6979995b8056dd70820314a0) Worldgen writes deep under a heightmap's surface skip its update ### 📊 Changes **3 files changed** (+76 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/heightmap.rs` (+12 -0) 📝 `crates/horizon-world/src/worldgen/terrain.rs` (+11 -4) 📝 `crates/horizon-world/tests/feature_region.rs` (+53 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. World generation writes every block of a proto chunk through `set_block_worldgen`, which updates each of the chunk's heightmaps per write. For a write two or more blocks under a heightmap's first available y, vanilla's `Heightmap.update` returns at once, but our path still went through `update_heightmap` for every map: a packed read, the chunk check and several `Result` branches, on writes that are mostly 50-300 blocks under the surface (noise fill, stone to deepslate, ore veins, carvers). `Heightmap::below_update` answers that case with one packed read; `set_block_worldgen` then only checks the state as before and skips the update. The other cases still call `update_heightmap` unchanged, so the maps are the same. Test: `feature_region::worldgen_writes_keep_heightmaps_as_updating_each_write` primes the maps of a Biomes-stage and a Terrain-stage chunk, then makes 20 000 random writes (mostly air/stone/water around the surface and under it) through `set_block_worldgen` and, on a copy, through `set_block_raw` + `update_heightmap` per map; heightmaps and blocks must be equal. ## Numbers playhorizon (Linux, 8 vCPU, `taskset 0-3`, load ~40), `chunkgen_bench --size 24 --threads 1` (576 proto chunks), 4 alternating A/B pairs: | | main | this PR | |---|---|---| | CPU per proto chunk | 10.65 ms | 10.35 ms (-2.8%, faster in 4 of 4 pairs) | Generation output is unchanged (harnesses below). Not measured: world entry in perf_bench and many-core scaling (the fleet machines were loaded 20-45 all night; CPU time per chunk is the reliable number then). **Parity** (`tools/parity.py` on playhorizon at 340dfd1d3e, the generation and light harnesses of the 383 it selects; CI runs the rest): 10 passed, 0 failed in 41.1 min: chunk_generation, decorated_region, decoration, heightmap, light, material_surface, retrogen_chunk, server_world_gen, worldgen, worldgen_random (chunk_generation passed on its retry without reused oracle results). **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 06f842dc3, 21 min 42 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +76 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 595 passed (1 min 18 s) | | rustfmt | ✅ (15 s) | | clippy | ✅ (9 min 1 s) | | tests: horizon-world | ✅ 376 passed (10 min 21 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 | ➖ 202 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, attribute_updates, audio_attributes, auto_jump, bamboo, basic_feature, biome_chunk, biome_generation, biome_placement and 190 more | | 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 06:32: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#7046
No description provided.