Add benchmark to PathFinder and fix search hot spots - #959
Open
eduardosmaniotto wants to merge 1 commit into
Open
Add benchmark to PathFinder and fix search hot spots#959eduardosmaniotto wants to merge 1 commit into
eduardosmaniotto wants to merge 1 commit into
Conversation
Add tests/MUnique.OpenMU.Pathfinding.Benchmarks with scoped, full-grid, unreachable and MaximumDistance scenarios. Optimize hot paths without changing public API: - Point: add EuclideanDistanceSquaredTo, avoid Math.Pow - PathFinder: cached MaximumDistanceSquared, fixed Elapsed metrics bug (Stopwatch ticks vs TimeSpan ticks), removed dead null checks, single-pass path reconstruction - FullGridNetwork.Prepare: for loop instead of LINQ over 65k nodes - ScopedGridNetwork.Prepare: BitOperations.Log2 instead of Math.Log - BinaryMinHeap: method locals instead of shared int fields, clearer Swap/Compare helpers
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
No BenchmarkDotNet coverage existed for the A*/Dijkstra
PathFinder(only an ad-hoc
Stopwatchtest). This PR adds a dedicated benchmarkproject and fixes the hot spots it exposed, keeping all public APIs
unchanged.
New:
tests/MUnique.OpenMU.Pathfinding.Benchmarks/(
PathFinderBenchmarks.cs: short/diagonal/wall-detour/unreachable onScopedGridNetwork, long path onFullGridNetwork,MaximumDistancepath).Changes (
src/Pathfinding/)Point.cs:EuclideanDistanceSquaredTo()(int mult, noMath.Pow/Abs);EuclideanDistanceTo()reuses it.PathFinder.cs: cached_maximumDistanceSquared; squared distance checks with early-outs;Elapsed.TotalMillisecondsmetrics fix; removed deadHeuristicnull checks;GetCalculatedPath()builds + reverses oneList.FullGridNetwork.cs:Prepare()forloop instead of_nodes.Where(...)LINQ.ScopedGridNetwork.cs:BitOperations.Log2()instead ofMath.Log(x, 2).BinaryMinHeap{T}.cs: loop indices as locals instead of shared_i/_parentIndex/_left/_rightfields; renamed helpers toSwap/Compare.Benchmarks
dotnet run --project tests/MUnique.OpenMU.Pathfinding.Benchmarks -c Release -- --filter '*PathFinderBenchmarks*' --job short --warmupCount 2 --iterationCount 5Before:
After:
Verification
dotnet test tests/MUnique.OpenMU.Pathfinding.Tests -c Release: 9/9 passed.INetwork,IPriorityQueue<T>,IPathFinderuntouched).