Add optional async mob pathfinding#14029
Open
Rxflex wants to merge 1 commit into
Open
Conversation
Offload the A* search in PathFinder#findPath off the main server thread for mob navigation, gated per-world behind entities.behavior.async-pathfinding (default off). The request is prepared on the main thread (validation, EntityPathfindEvent, region snapshot) and only the expensive A* search runs on a worker pool using a thread-confined PathFinder instance; the finished Path is applied back on the main thread via the server executor. Failures fall back silently and the pool uses a caller-runs policy, so a saturated queue degrades to vanilla synchronous behaviour and never regresses past it. On expensive pathfinding (obstacle-dense areas, hard/unreachable targets) this removes ~90% of the per-path main-thread cost (measured ~1003us -> ~91us per path in a synthetic obstacle field). On trivial paths the offload overhead makes it roughly neutral, hence the opt-in default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in feature that moves the expensive A* search in mob pathfinding
(
PathFinder#findPath) off the main server thread onto a worker pool. Gatedper-world behind
entities.behavior.async-pathfinding(default off).How it works
check,
EntityPathfindEvent,PathNavigationRegionsnapshot).thread-confined
PathFindercreated per call — the shared, mutableNodeEvaluatoronthis.pathFinderis never touched off-thread.Pathis applied back on the main thread via the serverexecutor, so the world mutation model is unchanged.
moveTo(coords/entity, speed)overloads opt in;createPath(...)stays fully synchronous, so goals that inspect the pathdirectly keep exact vanilla behaviour.
Safety / no-regression
queue degrades to vanilla synchronous pathfinding — never worse than baseline.
Measured impact
Synthetic in-process benchmark (200 mobs, obstacle field, hard targets),
per-path main-thread cost:
~90% of main-thread pathfinding cost removed on expensive paths (the case
that actually causes MSPT spikes: obstacle-dense areas, hard/unreachable
targets, villages/farms). On trivial paths the offload overhead makes it
roughly neutral — hence the opt-in default.
Notes
a real multiplayer load, only via the isolated microbenchmark above.
data-race tradeoff (as shipped by other forks), mitigated by the try/catch
fallback.
PathFinderpool would cut the residual ~91 µsprep (dominated by per-call
NodeEvaluatorallocation) further.