-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[stdlib] ContiguousArray & ArraySlice: Stop swapping self in wUMBP #38898
Conversation
Implements #38867 for ContiguousArray and ArraySlice -- these have the same unnecessary swapping logic.
@swift-ci test |
@swift-ci benchmark |
Performance (x86_64): -O
Code size: -OPerformance (x86_64): -Osize
Code size: -OsizePerformance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
This reintroduces retain/release operations for the empty array until swiftlang/swift#38898 lands. Mitigate the performance costs of this by refactoring code to reduce the size of the inlined bubbleUpMin/Max invocations.
This reintroduces retain/release operations for the empty array until swiftlang/swift#38898 lands. Mitigate the performance costs of this by refactoring code to reduce the size of the inlined bubbleUpMin/Max invocations.
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.
Fewer instructions to do the same thing. LGTM
Surprisingly, swapping |
* [Heap] Don't always inline large functions * [docs] Use a stable link to the Atkinson article (The original link was pointing to course materials at a random university.) * Remove stray import * Revert "[Heap] Don't always inline large functions" This reverts commit 07ffd65. * [Heap] Enable code coverage collection in Xcode scheme * [Heap] Speed up invariant checking * [Heap] Precalculate levels for each offset `_Node` is a new struct that consists of a storage offset (the old index) along with its level in the tree. The level can be incrementally calculated, saving some time vs counting bits whenever it's needed. * [Heap] Switch to using unsafe buffer pointers Introduce `Heap._UnsafeHandle` (a thin wrapper around an unsafe buffer pointer) and rebase most heap algorithms on top of that instead of array operations. This simplifies things by reducing (hopefully) unnecessary index validation, resulting in some measurable performance improvements. * [Heap] Stop force-inlining bubbleUp; mark it releasenone Not inlining such a large function speeds things up by leaving some headroom for the optimizer to make better inlining decisions elsewhere. (Force inlining this resulted in the compiler not inlining the closure passed to `_update` instead, which isn't a great tradeoff. To speed things up, mark `bubbleUp` with `@_effects(releasenone)`. This may be questionable (because it calls `Element.<`), but it results in better codegen, making `insert` match the performance of `std::priority_queue`. * [Heap] Rework removals * [Heap] Remove dead code * [Heap] Switch to using _ContiguousArray as storage * [Heap] insert<S>(contentsOf:): add fast path for count == 0 case * [Heap] Perf pass on trickleDown code paths This improves popMin/popMax (and the sequence initializer) by reviewing trickleDown and optimizing things: - Replace swapAt with a scheme where we keep a hold in the storage buffer - Slightly shorten min/max dependency chain in primary sink loop In exchange, we get even less readable code. * [Heap] bubbleUp: remove @_effects attribute This reintroduces retain/release operations for the empty array until swiftlang/swift#38898 lands. Mitigate the performance costs of this by refactoring code to reduce the size of the inlined bubbleUpMin/Max invocations. * [Heap] Finetune Heap.insert
Implements #38867 for ContiguousArray and ArraySlice -- these have the same unnecessary swapping logic.