Skip to content
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

Avoid unnecessary allocations in PriorityQueue.EnqueueRange #50065

Merged

Conversation

eiriktsarpalis
Copy link
Member

While investigating the performance regression reported in #50052 I discovered an issue in the implementation of PriorityQueue.EnqueueRange where the call to EnumerableHelpers.ToArray will often result in unnecessary allocations of buffers.

Performance

Running the HeapSort benchmark from dotnet/performance:

main

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 169.1 ns 0.84 ns 0.70 ns 168.9 ns 168.4 ns 170.8 ns 0.0100 - - 104 B
HeapSort 100 2,639.9 ns 7.44 ns 6.60 ns 2,638.9 ns 2,626.4 ns 2,650.1 ns 0.0744 - - 824 B
HeapSort 1000 71,286.5 ns 271.46 ns 253.92 ns 71,274.5 ns 70,843.3 ns 71,722.1 ns 0.5605 - - 8,024 B

PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 151.8 ns 0.79 ns 0.62 ns 151.8 ns 150.7 ns 153.0 ns - - - -
HeapSort 100 2,582.6 ns 39.87 ns 33.30 ns 2,583.8 ns 2,515.2 ns 2,630.6 ns - - - -
HeapSort 1000 67,370.4 ns 222.44 ns 185.75 ns 67,386.2 ns 66,978.4 ns 67,707.7 ns - - - -

@ghost
Copy link

ghost commented Mar 23, 2021

Tagging subscribers to this area: @eiriktsarpalis
See info in area-owners.md if you want to be subscribed.

Issue Details

While investigating the performance regression reported in #50052 I discovered an issue in the implementation of PriorityQueue.EnqueueRange where the call to EnumerableHelpers.ToArray will often result in unnecessary allocations of buffers.

Performance

Running the HeapSort benchmark from dotnet/performance:

main

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 169.1 ns 0.84 ns 0.70 ns 168.9 ns 168.4 ns 170.8 ns 0.0100 - - 104 B
HeapSort 100 2,639.9 ns 7.44 ns 6.60 ns 2,638.9 ns 2,626.4 ns 2,650.1 ns 0.0744 - - 824 B
HeapSort 1000 71,286.5 ns 271.46 ns 253.92 ns 71,274.5 ns 70,843.3 ns 71,722.1 ns 0.5605 - - 8,024 B

PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 151.8 ns 0.79 ns 0.62 ns 151.8 ns 150.7 ns 153.0 ns - - - -
HeapSort 100 2,582.6 ns 39.87 ns 33.30 ns 2,583.8 ns 2,515.2 ns 2,630.6 ns - - - -
HeapSort 1000 67,370.4 ns 222.44 ns 185.75 ns 67,386.2 ns 66,978.4 ns 67,707.7 ns - - - -
Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Collections

Milestone: 6.0.0

@eiriktsarpalis eiriktsarpalis merged commit f000c7d into dotnet:main Mar 23, 2021
@eiriktsarpalis eiriktsarpalis deleted the priorityqueue-enqueuerange branch March 23, 2021 10:32
@ghost ghost locked as resolved and limited conversation to collaborators Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants