[PR #660] [MERGED] Pathfinder: Fx-hashed nodes, and each path type worked out once per query #2707

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

📋 Pull Request Information

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

Base: main ← Head: perf/pathfinder-caches


📝 Commits (1)

  • ed09e75 Pathfinder: hash nodes with the Fx hasher, and work out each path type once

📊 Changes

1 file changed (+22 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/mobs/path.rs (+22 -8)

📄 Description

What

Path searches (vanilla's PathFinder with WalkNodeEvaluator) were 14–16 % of tick_world in sample profiles of the busy world below, mostly villagers walking to their job sites, beds and meeting points. Two costs vanilla doesn't have:

  • Hashing: the node index and the per-query caches of path types and collision checks used the standard SipHash (2 % of the tick on its own); vanilla keys them by packed position in fastutil maps. They use the repository's Fx hasher now. Nothing iterates these maps, so no order changes.
  • Repeated path types: a position's static path type (getPathTypeStatic: its block, the one below, and up to 24 neighbours in checkNeighbourBlocks) was worked out again for every mob box that covered it: once as the bottom of one candidate node, again as the top of the node below, and again as "the current type" when a box held several. Vanilla caches the block part level-wide (ServerLevel.getPathTypeCache). The finder now remembers each position's type for the query.

Same results

A finder lives for one query (Mob::create_path_raw builds it, find consumes it), and the world doesn't change during a query, so a remembered type is the type the position would get again. The fly evaluator's type also depends on the mob's block position, which is fixed for the query. mob_ai (the vanilla pathfinding oracle) is 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
Villager brains (villager_brain::tick, mostly path searches), per run 0.73 / 0.83 / 0.78 ms 0.57 / 0.50 / 0.54 ms (−31 %)
All mob entity ticks, mean of 3 4.64 ms 4.28 ms (−8 %)
Tick CPU time, mean of 3 8.11 ms 7.74 ms (−4.5 %)
Tick p99, per run 13.0 / 14.7 / 14.9 ms 13.5 / 12.8 / 13.5 ms

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/660 **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/pathfinder-caches` --- ### 📝 Commits (1) - [`ed09e75`](https://github.com/horizon-rust/horizon/commit/ed09e757baafff66547f14945f3e7ae46a7e30df) Pathfinder: hash nodes with the Fx hasher, and work out each path type once ### 📊 Changes **1 file changed** (+22 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/path.rs` (+22 -8) </details> ### 📄 Description ## What Path searches (vanilla's `PathFinder` with `WalkNodeEvaluator`) were 14–16 % of `tick_world` in `sample` profiles of the busy world below, mostly villagers walking to their job sites, beds and meeting points. Two costs vanilla doesn't have: - **Hashing:** the node index and the per-query caches of path types and collision checks used the standard SipHash (2 % of the tick on its own); vanilla keys them by packed position in fastutil maps. They use the repository's Fx hasher now. Nothing iterates these maps, so no order changes. - **Repeated path types:** a position's static path type (`getPathTypeStatic`: its block, the one below, and up to 24 neighbours in `checkNeighbourBlocks`) was worked out again for every mob box that covered it: once as the bottom of one candidate node, again as the top of the node below, and again as "the current type" when a box held several. Vanilla caches the block part level-wide (`ServerLevel.getPathTypeCache`). The finder now remembers each position's type for the query. ## Same results A finder lives for one query (`Mob::create_path_raw` builds it, `find` consumes it), and the world doesn't change during a query, so a remembered type is the type the position would get again. The fly evaluator's type also depends on the mob's block position, which is fixed for the query. `mob_ai` (the vanilla pathfinding oracle) is 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 | | --- | ---: | ---: | | Villager brains (`villager_brain::tick`, mostly path searches), per run | 0.73 / 0.83 / 0.78 ms | **0.57 / 0.50 / 0.54 ms** (−31 %) | | All mob entity ticks, mean of 3 | 4.64 ms | **4.28 ms** (−8 %) | | Tick CPU time, mean of 3 | 8.11 ms | **7.74 ms** (−4.5 %) | | Tick p99, per run | 13.0 / 14.7 / 14.9 ms | 13.5 / 12.8 / 13.5 ms | ### 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:26 +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#2707
No description provided.