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

Pop performance (addresses #15) #20

Merged
merged 2 commits into from
Oct 16, 2019
Merged

Conversation

peteraisher
Copy link
Contributor

I've managed to get a decent speed-up for pop() without an extensive rewrite.

Profiling testPopPerformance() shows that ~ 70% of the execution time for pop() is taken up by MutableCollection.swapAt(_:_:) and another ~ 13% is Array.subscript.getter.

Implementing the swap and the sink inside a call to Array.withUnsafeMutableBufferPointer(_:) gives a speedup of around 9x (on the release build) on my machine and puts the performance of pop() on a level with push(_:) and remove(_:).

I think the performance gap must be a case of the compiler just not figuring out the optimization for pop(), since all of the other public functions which call sink(_:) and swim(_:) are plenty fast.

@davecom davecom merged commit 778333b into davecom:master Oct 16, 2019
@davecom
Copy link
Owner

davecom commented Oct 16, 2019

Thank you, @peteraisher. This is the best of both worlds—code that I can maintain and that addresses the issue. I really want to thank you for the care and consideration you put into it. I and all the other users of SwiftPriorityQueue thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants