[PR #6824] [MERGED] Worldgen: build the rotation table without cloning every block state six times #7117

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

📋 Pull Request Information

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

Base: main ← Head: perf/rotation-table


📝 Commits (1)

  • cbaf328 Worldgen: build the rotation table without cloning every block state six times

📊 Changes

1 file changed (+119 additions, -17 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/state_provider.rs (+119 -17)

📄 Description

Requested by Ransom

🤖 Opened by Vaspyyy's AI agent (Claude Code), not by Vaspyyy personally.

What and why

Fixes #6823.

StateProviderBindings::rotations builds its table once (rotation_table). The coral features' decode asks for it while the world data preload runs prepare_decoration, and a world's open waits for that preload (world.make_streaming ends right after preload.decoration). The table cloned every one of the registry's ~30k states once per direction and looked each clone up by hash, after a pass that keyed a BTreeMap by cloned block names. A samply profile of the preload showed it dominated by BlockState::clone and allocator frees.

Now:

  • a state with neither a full axis nor a full or horizontal facing family rotates to itself without a clone (most states);
  • a rotation that sets the value the state already has is the state itself;
  • the family map borrows its keys.

The table is the same. The new test rotations_turn_axis_and_facing_families_only (axis, horizontal facing, full facing keeping powered, a five-way facing and a plain block, with expected ids written out by hand) passes on both the old and the new rotation_table.

Timings

preload.decoration (trace step from #6761) goes from ~165 ms to ~120 ms.

The world's first frame only gains once #6729 is in. Before that, the server thread waits on the second sync-data read instead. python3 tools/startup_trace.py --world T --seed 1234 --runs 2 --warm, three rounds alternating builds, 6 runs each, Ryzen 7 5800X / RTX 3070 / NVMe, medians:

before after
on upstream/main: world.first_frame 1048 ms 1027 ms (−21)
on upstream/main: world.view_full 1722 ms 1696 ms (−26)
with #6729 (+ the biome reports on their own thread): world.first_frame 961 ms 944 ms (−17)

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

The table itself is unchanged (BlockStateProvider rotations); only how it's built changes.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --base upstream/main on PunyDev, against upstream/main at 435730a40, 2 min 41 s)

Check Result
Scope ✅ 1 files, +119 −17
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 602 passed (46 s)
rustfmt ✅ (9 s)
clippy ✅ (29 s)
tests: horizon-world ✅ 381 passed (1 min 16 s)
doc tests ✅ 0 passed (1 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 (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)

🤖 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/6824 **Author:** [@Vaspyyy](https://github.com/Vaspyyy) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/rotation-table` --- ### 📝 Commits (1) - [`cbaf328`](https://github.com/horizon-rust/horizon/commit/cbaf3287f69bd0f8a580c90aa7e857097860e344) Worldgen: build the rotation table without cloning every block state six times ### 📊 Changes **1 file changed** (+119 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/state_provider.rs` (+119 -17) </details> ### 📄 Description <!-- claude-projects-attribution: {"github_login":"Vaspyyy"} --> _Requested by **Ransom**_ > 🤖 Opened by Vaspyyy's AI agent (Claude Code), not by Vaspyyy personally. ## What and why Fixes #6823. `StateProviderBindings::rotations` builds its table once (`rotation_table`). The coral features' decode asks for it while the world data preload runs `prepare_decoration`, and a world's open waits for that preload (`world.make_streaming` ends right after `preload.decoration`). The table cloned every one of the registry's ~30k states once per direction and looked each clone up by hash, after a pass that keyed a `BTreeMap` by cloned block names. A samply profile of the preload showed it dominated by `BlockState::clone` and allocator frees. Now: - a state with neither a full `axis` nor a full or horizontal `facing` family rotates to itself without a clone (most states); - a rotation that sets the value the state already has is the state itself; - the family map borrows its keys. The table is the same. The new test `rotations_turn_axis_and_facing_families_only` (axis, horizontal facing, full facing keeping `powered`, a five-way facing and a plain block, with expected ids written out by hand) passes on both the old and the new `rotation_table`. ### Timings `preload.decoration` (trace step from #6761) goes from ~165 ms to ~120 ms. The world's first frame only gains once #6729 is in. Before that, the server thread waits on the second sync-data read instead. `python3 tools/startup_trace.py --world T --seed 1234 --runs 2 --warm`, three rounds alternating builds, 6 runs each, Ryzen 7 5800X / RTX 3070 / NVMe, medians: | | before | after | |---|---|---| | on upstream/main: `world.first_frame` | 1048 ms | 1027 ms (−21) | | on upstream/main: `world.view_full` | 1722 ms | 1696 ms (−26) | | with #6729 (+ the biome reports on their own thread): `world.first_frame` | 961 ms | 944 ms (−17) | ## 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 The table itself is unchanged (`BlockStateProvider` rotations); only how it's built changes. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --base upstream/main` on PunyDev, against upstream/main at 435730a40, 2 min 41 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +119 −17 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 602 passed (46 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (29 s) | | tests: horizon-world | ✅ 381 passed (1 min 16 s) | | doc tests | ✅ 0 passed (1 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 (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) | 🤖 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:34:13 +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#7117
No description provided.