Repository navigation
Reduce allocations in grid pathfinding queues - #1263
Open
AlexisDrogoul wants to merge 1 commit into
Open
AlexisDrogoul wants to merge 1 commit into
AlexisDrogoul wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused refactor preserves queue behavior, with no unresolved findings.
No open issues 🎉
What changed in this PR
Reduces allocations in grid pathfinding by replacing list-based priority-queue entries with compact typed entries.
Changes:
- Updates Dijkstra, A*, and JPS to use typed entries, removing unchecked casts.
- Preserves priority calculations and ordering using
Double.compare.
| File | Description |
|---|---|
| gama.core/src/gama/core/topology/grid/GamaSpatialMatrix.java | Introduces compact queue entries and updates all three pathfinding algorithms. |
Review effort: Balanced
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
Replace the anonymous
ArrayListobjects used as priority-queue entries in grid Dijkstra, A*, and JPS with a compact typed entry containing only the agent and its priority. This removes per-entry list/backing-array allocations and unchecked casts while preserving the existing priority values and ordering.Other performance opportunities identified
GamaSpatialMatrix.java:1195-1349); avoids multiple allocations for every enqueued cell across three algorithms.GridNeighborhood.java:67-96).openarray (GamaSpatialMatrix.java:1143,1195,1266,1327).GraphTopology.java:1139).List.indexOffor every edge while initializing Floyd-Warshall (FloydWarshallShortestPathsGAMA.java:156-157).indexOfscans per query (FloydWarshallShortestPathsGAMA.java:259-260,PathComputer.javamatrix route lookup).NBAStarPathfinder.java:159,217).NBAStarPathfinder.java:319).containschecks during spatial splitting (SpatialTransformations.java:2410).ArrayListgrowth (NoCacheNeighborhood.java:88).Validation
mvn -f gama.parent/pom.xml -pl ../gama.core -am -DskipTests -Plocal-dev compilepassed.