Comments (6)
The OrderedSet equality operator simply calls elementsEqual. It does not test for referential equality as array does. It probably should though. Could this be the cause of the issue?
from swift-collections.
The OrderedSet equality operator simply calls elementsEqual. It does not test for referential equality as array does.
@ingoem Hmm… the underlying storage of the OrderedSet
appears to be a ContiguousArray
value type. AFAIK the ContiguousArray
is copy-on-write and does hold its own reference pointer that could be used to return early from a "linear" comparison. So we are comparing two "value" types… but those value types might hold a reference type and we might assume those value types are smart enough to exit early if those references are equal… we think?
Maybe it's a good idea… if OrderedSet.elementsEqual
is not defined in swift-collections
that means we get the default Sequence
implementation of elementsEqual
which doesn't know we have a copy-on-write backing store? If we implement our own elementsEqual
(for OrderedSet
) then we can take advantage of that and forward the elementsEqual
check to the underlying ContiguousArray
value type?
Be that as it may… it's still a little weird that the "modern" SwiftUI.NavigationStack
leads to dozens of equality checks just to push and pop a view while the "legacy" SwiftUI.NavigationView
seems to work without those checks. I'm not sure there could be anything about the implementation of OrderedSet
(or OrderedDictionary
) that could be "fooling" SwiftUI… but maybe there is?
from swift-collections.
https://github.com/apple/swift/blob/main/stdlib/public/core/ContiguousArray.swift#L1318-L1321
@ingoem It looks like ContiguousArray
can return early from a reference equality check.
https://github.com/apple/swift/blob/main/stdlib/public/core/SequenceAlgorithms.swift#L319-L336
And the default implementation of elementsEqual
performs a linear scan.
from swift-collections.
@lorentey Any thoughts about migrating these equality checks to forward through to ContiguousArray
?
from swift-collections.
diff --git a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift
index 2977363..630aaf5 100644
--- a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift
+++ b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift
@@ -387,7 +387,7 @@ extension OrderedDictionary.Values: MutableCollection {
extension OrderedDictionary.Values: Equatable where Value: Equatable {
@inlinable
public static func ==(left: Self, right: Self) -> Bool {
- left.elementsEqual(right)
+ left._base._values == right._base._values
}
}
This diff fixes my perf issues and still passes the swift-collections
tests. I'm still seeing 17 equality checks just to push and pop a List
… but those checks are at least fast now.
from swift-collections.
#335 was merged and these equality checks are now fast when comparing equal identities… I'm still not clear why SwiftUI would need dozens of equality checks to compare a let
constant collection against itself… but I'm not sure there's anything left to do to optimize this from swift-collections
for now.
from swift-collections.
Related Issues (20)
- `Deque` lacks `capacity` HOT 2
- Support fixed-size `Deque` HOT 2
- OrderedDictionary decoding. HOT 1
- OrderedDictionary insert(at:) HOT 1
- OrderedDictionary `updateValue` autoclosure for insertion index
- Failed to resolve dependencies Dependencies could not be resolved because no versions HOT 1
- Ship Sendable annotations in 1.0.6 HOT 1
- `Heap` documentation does not explain what a heap is
- `Heap.insert(contentsOf:)` is quasilinear instead of linear complexity
- OrderedSet `append(contentsOf:)` with insertion check result/results
- Ship release 1.0.6 HOT 11
- Ship release 1.1.0 HOT 19
- BitArray's bitwise operations should allow operating on slices HOT 2
- Version 1.1.0 fails to compile HOT 11
- Add Privacy Manifest HOT 7
- The bundle at path Payload/MyApp.app/Frameworks/_CollectionsUtilities.framework has an invalid CFBundleIdentifier '_CollectionsUtilities' HOT 13
- Incorrect calculating offset for _BTree.findAnyIndex(forKey: Key)
- [1.1] Randomized test failure on CI
- Please Add Support for Multiset HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-collections.