You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Heap currently uses regular array subscripting to access the contents of its storage. Array access is pretty fast, but it includes index validation that is (hopefully) unnecessary in Heap's case. I expect the optimizer is able to get rid of these index validations in some (but not all) cases; but it probably makes sense to not have them in the first place.
Rework the low-level heap implementation to operate on UnsafeMutableBuffer storage instead, turning index checks into debug-mode assertions rather than unconditional preconditions.
To do this, it would make sense to introduce a Heap._UnsafeHandle or _UnsafeHeap struct that consists of an UnsafeMutableBufferPointer value, and move most heap operation to that. We'll need to have closure-based read and update helpers that expose a read-only (or read-write) view of the Array storage. (Similar to how Deque and OrderedSet's hash tables work.)
The text was updated successfully, but these errors were encountered:
The withUnsafeMutableBufferPointer implementations in Array and friends included ancient protection against concurrent mutations that actually made this slower than the original code for insert (but not for removals). This was fixed in the stdlib in swiftlang/swift#38867 & swiftlang/swift#38898. The insert code assumes these changes are in place, or else it will work a bit slower than expected. (These fixes ship in the stdlib SDK, so they're backdeployable. All we need to pick them up is to recompile the code with a future Swift release that contains them.)
Heap
currently uses regular array subscripting to access the contents of its storage. Array access is pretty fast, but it includes index validation that is (hopefully) unnecessary inHeap
's case. I expect the optimizer is able to get rid of these index validations in some (but not all) cases; but it probably makes sense to not have them in the first place.Rework the low-level heap implementation to operate on UnsafeMutableBuffer storage instead, turning index checks into debug-mode assertions rather than unconditional preconditions.
To do this, it would make sense to introduce a
Heap._UnsafeHandle
or_UnsafeHeap
struct that consists of an UnsafeMutableBufferPointer value, and move most heap operation to that. We'll need to have closure-basedread
andupdate
helpers that expose a read-only (or read-write) view of the Array storage. (Similar to how Deque and OrderedSet's hash tables work.)The text was updated successfully, but these errors were encountered: