[PR #661] [MERGED] Entity portal checks: skip the sweep where no section holds a portal #2706

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

📋 Pull Request Information

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

Base: main ← Head: perf/entity-portal-precheck


📝 Commits (1)

  • 1efc7f8 Entity portal checks: skip the sweep where no section holds a portal

📊 Changes

1 file changed (+65 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game/nether_portal.rs (+65 -2)

📄 Description

What

Every tick, each item and mob that can use a portal sweeps the blocks its box passed through since the last tick looking for a nether portal (Entity.checkInsideBlocks reaching NetherPortalBlock.entityInside): 3.3–4.7 % of tick_world in sample profiles of the busy world below. Each sweep allocated a SipHash visited set and read every block of the path.

Every block a sweep visits lies inside the box covering the entity's box at both ends. When no 16³ section that box touches (plus a block of margin) has a nether portal state in its palette, no visited block can be a portal, so the sweep is skipped. Sections are checked once per tick and remembered; a box over more than 64 sections (an entity teleported far) is swept as before. Nether travel searches already use the same palette test (maybe_has with portal_axis).

Same results

The skip only happens when the sweep could not find a portal, and the sweep's result is the only thing used (its errors were already ignored). The nether_portal and portal travel harnesses are in the parity run below.

Results

Base/new × 3 interleaved, the same world; thread CPU ms per tick from the probe's span totals:

Same world and settings main this PR
Entity portal checks (entity_portals), per run 0.312 / 0.310 / 0.334 ms 0.161 / 0.163 / 0.152 ms (−50 %)
Tick CPU time, per run 7.98 / 8.03 / 8.31 ms 8.32 / 8.56 / 7.91 ms
Tick p99, per run 13.0 / 14.7 / 14.9 ms 14.5 / 13.3 / 13.2 ms

What is left of entity_portals is the bookkeeping before the entities move (positions, cooldowns). The whole tick swings by more than this saving between runs on this loaded machine (mob movement alone differed by 0.15 ms between these runs).

How it was measured

  • Machine: Mac mini M4 Pro (14 cores, Metal), shared with other agents' builds and harnesses (load average 60–110 during these runs), so absolute times swing from run to run: compare columns of the same table. Tick times are the integrated server tick in thread CPU time (a local, uncommitted probe times Game::tick with CLOCK_THREAD_CPUTIME_ID, so time spent descheduled doesn't count; the same probe sums the existing spans per tick).
  • World: seed 1234, creative, next to the village of the village benchmark scene (-960, 66, 176), night (time set 18000, advance_time false), a fenced pen with 400 summoned mobs (80 villagers, 80 cows, 80 sheep, 60 zombies, 60 chickens, 40 pigs), about 510 mobs in all. Saved once and restored before every run. Render distance 12, offscreen 1280×720, fast profile (release without LTO).
  • Run: load, wait until no chunk is pending, 300 ticks of warm-up, then bench 40 (about 800 ticks). Builds interleaved base/new.

Self-check

Run on one integration commit holding this PR and the four other server-tick PRs of this round (structure starts, collision scans, entity portal checks, sculk scan, pathfinder caches), which touch separate code:

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client --lib: 787 passed, 0 failed (10 ignored). cargo test -p horizon-world -p horizon-core: all passed.
  • Local parity, tools/parity.py --changed origin/main on the integration commit (all five PRs together, 309 harnesses depend on the changed files): 194 passed, 0 failed; the other 115 did not run because the run hit the 2 h background limit. The passes are in the shared pass cache, so a rerun of the same tree only runs the remaining 115.

Nothing needs Ludovic.

🤖 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/661 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/entity-portal-precheck` --- ### 📝 Commits (1) - [`1efc7f8`](https://github.com/horizon-rust/horizon/commit/1efc7f83d180f43838b8295c24ec5a28a83778b8) Entity portal checks: skip the sweep where no section holds a portal ### 📊 Changes **1 file changed** (+65 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/nether_portal.rs` (+65 -2) </details> ### 📄 Description ## What Every tick, each item and mob that can use a portal sweeps the blocks its box passed through since the last tick looking for a nether portal (`Entity.checkInsideBlocks` reaching `NetherPortalBlock.entityInside`): 3.3–4.7 % of `tick_world` in `sample` profiles of the busy world below. Each sweep allocated a SipHash visited set and read every block of the path. Every block a sweep visits lies inside the box covering the entity's box at both ends. When no 16³ section that box touches (plus a block of margin) has a nether portal state in its palette, no visited block can be a portal, so the sweep is skipped. Sections are checked once per tick and remembered; a box over more than 64 sections (an entity teleported far) is swept as before. Nether travel searches already use the same palette test (`maybe_has` with `portal_axis`). ## Same results The skip only happens when the sweep could not find a portal, and the sweep's result is the only thing used (its errors were already ignored). The `nether_portal` and portal travel harnesses are in the parity run below. ## Results Base/new × 3 interleaved, the same world; thread CPU ms per tick from the probe's span totals: | Same world and settings | `main` | this PR | | --- | ---: | ---: | | Entity portal checks (`entity_portals`), per run | 0.312 / 0.310 / 0.334 ms | **0.161 / 0.163 / 0.152 ms** (−50 %) | | Tick CPU time, per run | 7.98 / 8.03 / 8.31 ms | 8.32 / 8.56 / 7.91 ms | | Tick p99, per run | 13.0 / 14.7 / 14.9 ms | 14.5 / 13.3 / 13.2 ms | What is left of `entity_portals` is the bookkeeping before the entities move (positions, cooldowns). The whole tick swings by more than this saving between runs on this loaded machine (mob movement alone differed by 0.15 ms between these runs). ### How it was measured - **Machine:** Mac mini M4 Pro (14 cores, Metal), shared with other agents' builds and harnesses (load average 60–110 during these runs), so absolute times swing from run to run: compare columns of the same table. Tick times are the integrated server tick in **thread CPU time** (a local, uncommitted probe times `Game::tick` with `CLOCK_THREAD_CPUTIME_ID`, so time spent descheduled doesn't count; the same probe sums the existing `spans` per tick). - **World:** seed 1234, creative, next to the village of the `village` benchmark scene (-960, 66, 176), night (`time set 18000`, `advance_time false`), a fenced pen with 400 summoned mobs (80 villagers, 80 cows, 80 sheep, 60 zombies, 60 chickens, 40 pigs), about 510 mobs in all. Saved once and restored before every run. Render distance 12, offscreen 1280×720, `fast` profile (release without LTO). - **Run:** load, wait until no chunk is pending, 300 ticks of warm-up, then `bench 40` (about 800 ticks). Builds interleaved base/new. ### Self-check Run on one integration commit holding this PR and the four other server-tick PRs of this round (structure starts, collision scans, entity portal checks, sculk scan, pathfinder caches), which touch separate code: - `cargo fmt --all --check`: clean. - `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client --lib`: 787 passed, 0 failed (10 ignored). `cargo test -p horizon-world -p horizon-core`: all passed. - Local parity, `tools/parity.py --changed origin/main` on the integration commit (all five PRs together, 309 harnesses depend on the changed files): **194 passed, 0 failed**; the other 115 did not run because the run hit the 2 h background limit. The passes are in the shared pass cache, so a rerun of the same tree only runs the remaining 115. Nothing needs Ludovic. 🤖 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-02 15:58:25 +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#2706
No description provided.