[PR #758] [MERGED] Portal scans: keep per-chunk section masks across ticks #2785

Closed
opened 2026-11-02 15:59:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/758
Author: @rdbtCVS
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ludovic111

Base: main ← Head: perf/portal-section-mask


📝 Commits (1)

  • c4cc795 Portal scans: keep per-chunk section masks across ticks

📊 Changes

7 files changed (+490 additions, -18 deletions)

View changed files

➕ crates/horizon-client/examples/portal_scan_bench.rs (+263 -0)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/nether_portal.rs (+20 -18)
📝 crates/horizon-client/src/game/packs.rs (+1 -0)
📝 crates/horizon-client/src/lib.rs (+1 -0)
➕ crates/horizon-client/src/portal_sections.rs (+123 -0)
➕ docs/portal-scan-benchmark.md (+81 -0)

📄 Description

🤖 Opened by rdbt's AI agent (opencode), not by rdbt himself.

What

Game::may_hold_portal, the precheck #661 added ahead of the nether-portal sweep, asked each reach's sections whether their palette holds a portal, and remembered the per-section answer only for the current tick (FxHashMap<(i32, i32, i32), bool>). A section's palette answer changes only when its chunk's blocks change, so it is kept across ticks now:

  • crates/horizon-client/src/portal_sections.rs (new): PortalSections, a per-chunk u32 mask of the sections whose palette may hold a portal, keyed by (cx, cz) and validated by a Weak<Chunk>. An edit (Arc::make_mut moves a chunk while a weak handle exists) or a replacement rebuilds the mask, and the weak handle retains no block data. It mirrors random_tick_sections.
  • may_hold_portal builds the reach's y mask and tests it against the cached chunk mask; the per-tick map is gone.
  • The cache is cleared when the block facts change (game/packs.rs) and an entry is dropped when a chunk unloads (sync_tick_chunks in game.rs).

Same results

The example runs the original seen-map precheck and the cached one in one binary and asserts they agree for every reach over every sample (assert_eq! in crates/horizon-client/examples/portal_scan_bench.rs). portal_sections has unit tests for edits, section compaction, chunk replacement at the same coordinates, an early weak snapshot, a chunk unload and a global palette covering the whole ID range. cargo test -p horizon-client: 917 passed, 13 ignored.

Results

docs/portal-scan-benchmark.md, the scan alone, microseconds per tick, median of seven paired samples, fast profile:

Palette Original Cached Speedup
sparse, steady 40.058 16.836 2.38x
dense, steady 244.610 21.869 11.19x
global, steady 6179.070 360.082 17.16x
dense + portals, steady 256.854 21.078 12.19x

Steady improves 2.4x to 17x. Constant edits still win for the dense and global palettes (edit_1pct 3-4x), because the original rescans through the per-tick map. Rescanning every chunk every tick (cold, reload, edit_all) is slower: a miss reads all 24 sections of a chunk, where the original touched only the sections a reach overlaps. The global palette's maybe_has walks the whole ID range, so those rows are not measured for it.

This is a controlled fixture, not a whole-game claim: real terrain's palette sizes and write rate set the gain. The cache adds a weak handle and a mask per visited resident chunk, retains no unloaded block data, and editing a cached chunk can move its 176-byte wrapper on the first edit (it does not copy the block data).

How it was measured

AMD Ryzen 5 5600X (12 logical CPUs), Linux x86-64, rustc 1.99.0 (b940084d7), fast (release optimization, LTO off, 16 codegen units). The fixture is a 17x17 chunk world (289 chunks) of 24 sections with 500 entity reaches over it, in four palette variants; resource loading 705 ms, fixture construction 66-392 ms shared by both implementations. Each workload has one discarded warmup pair and seven measured pairs of 300 ticks.

Self-check

  • cargo fmt --all -- --check: clean.
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: 917 passed, 13 ignored.
  • The parity harnesses were not run here: they need the maintainer's game files, and this change is in crates/horizon-client with no portal-scan oracle. The scan is parity-checked in the example run above.

Nothing needs Ludovic.


🔄 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/758 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/portal-section-mask` --- ### 📝 Commits (1) - [`c4cc795`](https://github.com/horizon-rust/horizon/commit/c4cc7954cecbee7639f11f7a0b21d383311d948d) Portal scans: keep per-chunk section masks across ticks ### 📊 Changes **7 files changed** (+490 additions, -18 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/portal_scan_bench.rs` (+263 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/nether_portal.rs` (+20 -18) 📝 `crates/horizon-client/src/game/packs.rs` (+1 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) ➕ `crates/horizon-client/src/portal_sections.rs` (+123 -0) ➕ `docs/portal-scan-benchmark.md` (+81 -0) </details> ### 📄 Description > 🤖 Opened by rdbt's AI agent (opencode), not by rdbt himself. ## What `Game::may_hold_portal`, the precheck #661 added ahead of the nether-portal sweep, asked each reach's sections whether their palette holds a portal, and remembered the per-section answer only for the current tick (`FxHashMap<(i32, i32, i32), bool>`). A section's palette answer changes only when its chunk's blocks change, so it is kept across ticks now: - `crates/horizon-client/src/portal_sections.rs` (new): `PortalSections`, a per-chunk `u32` mask of the sections whose palette may hold a portal, keyed by `(cx, cz)` and validated by a `Weak<Chunk>`. An edit (`Arc::make_mut` moves a chunk while a weak handle exists) or a replacement rebuilds the mask, and the weak handle retains no block data. It mirrors `random_tick_sections`. - `may_hold_portal` builds the reach's `y` mask and tests it against the cached chunk mask; the per-tick map is gone. - The cache is cleared when the block facts change (`game/packs.rs`) and an entry is dropped when a chunk unloads (`sync_tick_chunks` in `game.rs`). ## Same results The example runs the original `seen`-map precheck and the cached one in one binary and asserts they agree for every reach over every sample (`assert_eq!` in `crates/horizon-client/examples/portal_scan_bench.rs`). `portal_sections` has unit tests for edits, section compaction, chunk replacement at the same coordinates, an early weak snapshot, a chunk unload and a global palette covering the whole ID range. `cargo test -p horizon-client`: 917 passed, 13 ignored. ## Results `docs/portal-scan-benchmark.md`, the scan alone, microseconds per tick, median of seven paired samples, `fast` profile: | Palette | Original | Cached | Speedup | | --- | ---: | ---: | ---: | | sparse, steady | 40.058 | 16.836 | 2.38x | | dense, steady | 244.610 | 21.869 | 11.19x | | global, steady | 6179.070 | 360.082 | 17.16x | | dense + portals, steady | 256.854 | 21.078 | 12.19x | Steady improves 2.4x to 17x. Constant edits still win for the dense and global palettes (edit_1pct 3-4x), because the original rescans through the per-tick map. Rescanning every chunk every tick (cold, reload, edit_all) is slower: a miss reads all 24 sections of a chunk, where the original touched only the sections a reach overlaps. The global palette's `maybe_has` walks the whole ID range, so those rows are not measured for it. This is a controlled fixture, not a whole-game claim: real terrain's palette sizes and write rate set the gain. The cache adds a weak handle and a mask per visited resident chunk, retains no unloaded block data, and editing a cached chunk can move its 176-byte wrapper on the first edit (it does not copy the block data). ## How it was measured AMD Ryzen 5 5600X (12 logical CPUs), Linux x86-64, rustc 1.99.0 (b940084d7), `fast` (release optimization, LTO off, 16 codegen units). The fixture is a 17x17 chunk world (289 chunks) of 24 sections with 500 entity reaches over it, in four palette variants; resource loading 705 ms, fixture construction 66-392 ms shared by both implementations. Each workload has one discarded warmup pair and seven measured pairs of 300 ticks. ## Self-check - `cargo fmt --all -- --check`: clean. - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: 917 passed, 13 ignored. - The parity harnesses were not run here: they need the maintainer's game files, and this change is in `crates/horizon-client` with no portal-scan oracle. The scan is parity-checked in the example run above. Nothing needs Ludovic. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:59:01 +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#2785
No description provided.