[PR #1804] [MERGED] Surface: specialise the material rule per height band #3776

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1804
Author: @kacpherek
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/25/2026
Merged by: @ludovic111

Base: main ← Head: pr/surface-rule-bands


📝 Commits (1)

  • dbafda0 Surface: specialise the material rule per gradient band and surface side

📊 Changes

3 files changed (+244 additions, -3 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/material_condition.rs (+75 -0)
📝 crates/horizon-world/src/worldgen/material_condition/rule.rs (+158 -1)
📝 crates/horizon-world/src/worldgen/material_stage.rs (+11 -2)

📄 Description

What and why

The surface stage is the biggest single cost of making a new chunk. In a profile of pre-generation it took about 37% of worker time.

Most of that time goes into walking the whole surface rule tree for every block, even deep underground, where almost none of it can apply.

This change compiles each chunk's rule once into a few smaller versions:

  • one for each band of height that the rule's vertical gradients split the world into (bedrock_floor, deepslate and so on);
  • one for blocks below the preliminary surface, and one for blocks at or above it, when the rule asks about it.

Conditions that these facts already decide are removed from that version. A deep stone block then only checks the rules that can still apply there, like ore veins and the underground rules.

Conditions only read the position and the world, they never change anything, so the result is the same block for every position. The versions come from whatever rules are loaded, so data pack and modded surface rules work the same way.

Measured: surface stage on one thread, seed 1234: 2.45 ms per chunk before, 2.08 ms after (15% less).

Same output: chunkgen_bench --snapshot dumps the terrain and decorated stages at four sites (two Overworld seeds, the Nether and the End). The output is byte-identical to the same build without this change.

Vanilla reference

SurfaceSystem.buildSurface and SurfaceRules (SequenceRuleSource, TestRuleSource, VerticalGradientConditionSource, AbovePreliminarySurface). CI's parity job picks the surface harnesses this touches.

Self-check

pr_ready (tools/pr_ready.py on device-591, against origin/main at 6a065fa48, 1 min 17 s)

Check Result
Scope ✅ 3 files, +244 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (30 s)
tests: horizon-world ✅ 236 passed (40 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (no vanilla data here): 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)

🔄 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/1804 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `pr/surface-rule-bands` --- ### 📝 Commits (1) - [`dbafda0`](https://github.com/horizon-rust/horizon/commit/dbafda06ed699a4e6e2653abd2aaa620fcfb1859) Surface: specialise the material rule per gradient band and surface side ### 📊 Changes **3 files changed** (+244 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/material_condition.rs` (+75 -0) 📝 `crates/horizon-world/src/worldgen/material_condition/rule.rs` (+158 -1) 📝 `crates/horizon-world/src/worldgen/material_stage.rs` (+11 -2) </details> ### 📄 Description ## What and why The surface stage is the biggest single cost of making a new chunk. In a profile of pre-generation it took about 37% of worker time. Most of that time goes into walking the whole surface rule tree for every block, even deep underground, where almost none of it can apply. This change compiles each chunk's rule once into a few smaller versions: - one for each band of height that the rule's vertical gradients split the world into (`bedrock_floor`, `deepslate` and so on); - one for blocks below the preliminary surface, and one for blocks at or above it, when the rule asks about it. Conditions that these facts already decide are removed from that version. A deep stone block then only checks the rules that can still apply there, like ore veins and the underground rules. Conditions only read the position and the world, they never change anything, so the result is the same block for every position. The versions come from whatever rules are loaded, so data pack and modded surface rules work the same way. **Measured:** surface stage on one thread, seed 1234: 2.45 ms per chunk before, 2.08 ms after (15% less). **Same output:** `chunkgen_bench --snapshot` dumps the terrain and decorated stages at four sites (two Overworld seeds, the Nether and the End). The output is byte-identical to the same build without this change. ## Vanilla reference `SurfaceSystem.buildSurface` and `SurfaceRules` (`SequenceRuleSource`, `TestRuleSource`, `VerticalGradientConditionSource`, `AbovePreliminarySurface`). CI's parity job picks the surface harnesses this touches. ## Self-check **pr_ready** (`tools/pr_ready.py` on device-591, against origin/main at 6a065fa48, 1 min 17 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +244 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (30 s) | | tests: horizon-world | ✅ 236 passed (40 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (no vanilla data here): 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) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:12:14 +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#3776
No description provided.