You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR optimizes Pathfinder::checkForAdjust by eliminating a redundant clientSafeQuickDoesPathExist call in the non-aircraft code path.
Previously, adjustedPathExists (path from object position to the adjusted destination) was always computed eagerly, then unconditionally overwritten to true when !pathExists && C — wasting one pathfinding query in that branch. The new code short-circuits: only compute the adjusted-path check when the override condition is false.
The logic is semantically identical across all three cases (pathExists=T, pathExists=F && C=T, pathExists=F && C=F), and adjustedPathExists is always initialized through the exhaustive if/else branches.
Confidence Score: 5/5
Safe to merge — the refactored branch produces identical Boolean outcomes across all three input combinations while skipping one pathfinding call in the !pathExists && dest→adjustDest case.
The logic change is a straightforward short-circuit optimization. All three cases (path exists, path missing with fallback reachable, path missing with fallback unreachable) were verified to yield the same value for adjustedPathExists as the original code. adjustedPathExists is always initialized through the exhaustive if/else, and the scope of pathExists is cleanly narrowed to the non-aircraft branch.
Refactors checkForAdjust to skip a redundant path-existence query; logic is equivalent to the original across all three Boolean cases, and adjustedPathExists is always initialized.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[checkForAdjust called] --> B{obj is AIRCRAFT?}
B -- Yes --> C[adjustedPathExists = true]
B -- No --> D["pathExists = doesPathExist(pos → dest)"]
D --> E{"!pathExists AND\ndoesPathExist(dest → adjustDest)?"}
E -- Yes --> F[adjustedPathExists = true\n⚡ Skip redundant B call]
E -- No --> G["adjustedPathExists =\ndoesPathExist(pos → adjustDest)"]
C --> H{adjustedPathExists?}
F --> H
G --> H
H -- Yes --> I["*dest = adjustDest\nreturn true"]
H -- No --> J[return false]
style F fill:#d4edda,stroke:#28a745
style G fill:#fff3cd,stroke:#ffc107
stephanmeesters
changed the title
perf(pathfinding): Skip redundant path-exists check in checkForAdjust
perf(pathfinder): Skip redundant path-exists check in checkForAdjust
Jun 14, 2026
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
GenRelates to GeneralsMinorSeverity: Minor < Major < Critical < BlockerPerformanceIs a performance concernZHRelates to Zero Hour
2 participants
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.
In
Pathfinder::checkForAdjustthere could be an unnecessary computation ofadjustedPathExistsbecause it could be overwritten later.The gain is minor:
adjustedPathExiststakes around 200 +- 150 ns, but can be called many times in an update frame