Skip to content

Pathfinding Parallelization#106

Merged
SoloByte merged 12 commits intomainfrom
pathfinding-parallelization
Nov 4, 2025
Merged

Pathfinding Parallelization#106
SoloByte merged 12 commits intomainfrom
pathfinding-parallelization

Conversation

@SoloByte
Copy link
Collaborator

This pull request adds parallel processing option to the Pathfinder class. Additionally, paths can now be requested asynchronous and multiple paths can be requested at once to be processed in parallel.

The Path class was overhauled to be pooled (minimizing small heap allocations) and the access to the internal rects list is now a readonly view for better clarity. Once a Path is recieved by an agent or returned from the standalone GetPath() functions it can be used or copied but it should not be modified. It has to be returned to the pool once it is no longer needed. After returning a Path instance it should no longer be accessed.

The internal AStar class was changed from a static class to an instance class. This allows each thread (when parallel processing is enabled) to have its own AStar instance.

New Feature: GetPathsParallel function added to process a batch of path requests outside the agent system in parallel.
Refactor: Pathfinder constructor expanded with initial capacities for internal collections and parallelProcessing/ pathRequests parameters.
…view or a copy of the rects list.

Feat: Added a new Copy() method for copying an existing path (deep copy).
@SoloByte SoloByte added this to the 5.0 milestone Oct 31, 2025
@SoloByte SoloByte self-assigned this Oct 31, 2025
@SoloByte SoloByte requested a review from Copilot October 31, 2025 09:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces object pooling and parallel processing capabilities to the pathfinding system to improve performance and reduce allocations.

Key changes include:

  • Implemented object pooling for Path instances to minimize garbage collection overhead
  • Converted AStar from a static class to an instance-based class to support thread-local usage
  • Added parallel processing support for handling multiple path requests concurrently
  • Made collection capacities configurable via constructor parameters to optimize memory allocation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 24 comments.

Show a summary per file
File Description
ShapeEngine/Pathfinding/Pathfinder.cs Added parallel processing toggle, configurable capacity parameters, thread-local AStar instances, and methods for parallel path computation
ShapeEngine/Pathfinding/Path.cs Implemented object pooling with rent/return methods, changed from immutable to mutable design, added helper methods for pool management
ShapeEngine/Pathfinding/IPathfinderAgent.cs Added documentation about path pooling requirements
ShapeEngine/Pathfinding/AStar.cs Converted from static to instance-based class, added async pathfinding support, integrated with Path pooling system
Examples/Scenes/ExampleScenes/PathfinderExample2.cs Updated to use new parallel processing feature and properly return paths to the pool
Examples/Scenes/ExampleScenes/PathfinderExample.cs Added path cleanup logic to properly return paths to the pool
Comments suppressed due to low confidence (1)

ShapeEngine/Pathfinding/IPathfinderAgent.cs:1

  • Corrected spelling of 'classed' to 'class' in documentation.
namespace ShapeEngine.Pathfinding;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Feat: PathfinderExample2 player can now spawn obstacles.
Refactor: General cleanup, typos fixed, some docs improved.
Fix: Node ApplyNodeValue did only apply node value when no layer was used or when layer did not exist. Values were never applied for existing layers.
… cost management

Refactor: NodeWeight Cur value calculation changed.
@SoloByte SoloByte merged commit 7ef4a25 into main Nov 4, 2025
7 checks passed
@SoloByte SoloByte deleted the pathfinding-parallelization branch November 4, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants