-
Notifications
You must be signed in to change notification settings - Fork 280
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
Borrowable container prototype #411
base: future
Are you sure you want to change the base?
Conversation
…xtracting(last:) Also generalize some members to support ~Copyable elements
- protocol BorrowingIteratorProtocol - protocol Container - protocol BidirectionalContainer - protocol RandomAccessContainer
- Bump to Xcode 16 - Update file lists - Switch to Swift 6 language mode and enable a bunch of experimental features
|
@swift-ci test |
|
@swift-ci test |
Instead, just have a regular class holding a HypoDeque. This requires two allocations per deque, but it makes representation a lot more straightforward. I do not have a workable solution for empty singletons, though.
105a844
to
626e24f
Compare
|
Welp, replacing ManagedBuffer had a significant performance impact. Comparing results between f64aded and 626e24f: That 7.3x slowdown for
|
…age class It turns out the major slowdowns in individual element add/remove operations were mostly caused by runtime exclusivity checking on `Deque._Storage._value`.
…unchecked:) Also, use these to spare some unnecessary instructions.
…lizeAll overloads
Maybe not -- these benchmarks were taken on a Linux VM, and I don't have a good instinct on the complexity of the default allocator there. |





This is a very early draft of an in-memory container construct that supports noncopyable elements and provides direct borrowing access to its storage.
Containerprotocol is a noncopyable amalgamation of multi-passSequencetypes and a limited subset ofCollection. The same construct provides both iteration and indexing.Spans over in-memory storage. Indices are better integrated with iterators -- we can start an iterator at a given index, and retrieve the index for the current position of any iterator.Containerhas aBorrowingIteratorProtocolsister protocol. This may get merged intoContainerto reduce the number of conformances needed, but initial drafts implied that would not lead to a satisfying user experience.Containerhas no equivalent forIndicesnorSubSequence. If stored borrows become a thing, then these may come back, although perhaps not as customizable associated types.BidirectionalContainerandRandomAccessContainerreplicating the old collection hierarchy. I decided against doing cleverassociatedtype BidirectionalIndextrickery to reduce the number of protocols; although that idea solves some vexing issues with conditional conformances, initial drafts indicated that it obfuscates things too much.This PR also adds some new types that conform to the new protocols:
HypoArraytype is a noncopyable, heap-allocated, not implicitly resizing (but explicitly resizable) variant ofArraythat supports noncopyable elements. ("Hypo-" hints at "under" or "bottom". It pains me to capitalize the name like this; we may return toHypoarraylater.)DynoArraytype is a noncopyable, heap-allocated, implicitly resizing variant ofArraythat supports noncopyable elements. (This roughly corresponds tostd::vectorin C++.) ("Dyn-" hints at "force" or "power".)HypoDequeandDynoDequetypes implement the same variants forDeque.HypoDequeis in fact directly using its unsafe handle as its storage representation.)Array's case, this handle type is roughly the same asOutputSpan. However,Arrayis a special case; it is unclear if doing this would make sense for other data structures.Dequeis reformulated to use the same unsafe handle type asHypoDequeandDynoDeque.The immediate next item on my todo list is to investigate the last item's impact on
Deque's performance.Checklist