-
Notifications
You must be signed in to change notification settings - Fork 5k
PriorityQueue: Apply Comparer<T>.Default optimization #48346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PriorityQueue: Apply Comparer<T>.Default optimization #48346
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
@@ -157,7 +162,14 @@ public void Enqueue(TElement element, TPriority priority) | |||
|
|||
// Restore the heap order | |||
int lastNodeIndex = GetLastNodeIndex(); | |||
MoveUp((element, priority), lastNodeIndex); | |||
if (_comparer == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
I think we could do better. I'll follow up with another PR. |
Make direct calls to
Comparer<T>.Default.Compare
when no customIComparer<T>
instance is specified, taking advantage of the optimizations in #48160.Performance
Using benchmarks from dotnet/performance#1665
main
PR branch