PriorityQueue: Apply Comparer<T>.Default optimization#48346
PriorityQueue: Apply Comparer<T>.Default optimization#48346stephentoub merged 5 commits intodotnet:masterfrom
Conversation
|
Tagging subscribers to this area: @eiriktsarpalis Issue DetailsMake direct calls to PerformanceUsing benchmarks from dotnet/performance#1665 main
PR branch
|
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Show resolved
Hide resolved
| // Restore the heap order | ||
| int lastNodeIndex = GetLastNodeIndex(); | ||
| MoveUp((element, priority), lastNodeIndex); | ||
| if (_comparer == null) |
There was a problem hiding this comment.
This approach attempts to minimize the number of times we null check _comparer per API call, but perhaps things would be simpler if we moved everything behind one MoveUp/MoveDown method that performs the check, potentially redundantly.
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
…c/PriorityQueue.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
stephentoub
left a comment
There was a problem hiding this comment.
Do we have sufficient tests now that we need to cover value types vs reference types with and without a custom comparer and where that comparer is and is not the default?
…c/PriorityQueue.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
I think we could do better. I'll follow up with another PR. |
Make direct calls to
Comparer<T>.Default.Comparewhen no customIComparer<T>instance is specified, taking advantage of the optimizations in #48160.Performance
Using benchmarks from dotnet/performance#1665
main
PR branch