Closed vanvoorden closed 5 months ago
@swift-ci test
@ingoem thanks for suggesting the reference equality check!
@vanvoorden Can you please rebase this PR on top of the release/1.0
branch, rather than main
?
I think it would make sense to ship this in the next patch release, rather than having it linger on main indefinitely.
I think it would make sense to ship this in the next patch release, rather than having it linger on main indefinitely.
@lorentey Sounds good. Thanks!
@lorentey Is there a CI job that can run Benchmarks
on a diff to detect for regressions or improvements against base
?
Here are benchmarks running locally. The reason that OrderedDictionary.==
is scaling linearly is because we are waiting on https://github.com/apple/swift-collections/pull/340. Optimizing the OrderedSet
equality will optimize this one.
@lorentey Thanks for reviewing!
@swift-ci test
(AFAIK, CI runs are still expected to fail on macOS. This is "fine", and it won't block us from landing this.)
Background
https://github.com/apple/swift-collections/issues/334
The current implementation of
OrderedDictionary.Values.==
forwards toSequence.elementsEqual
, which needs to perform a linear-time (O[N]
) comparison over both collections.[1]Since the "backing store" of our
OrderedDictionary.Values
is aContiguousArray
, we can forward that equality check through toContiguousArray
. If bothValues
instances point to the same identity, theContiguousArray
implementation will return early from the comparison.[2]We perform a similar check (against the
ContiguousArray
) in our implementation ofOrderedDictionary.==
.[3][1] https://github.com/apple/swift/blob/main/stdlib/public/core/SequenceAlgorithms.swift#L319-L336 [2] https://github.com/apple/swift/blob/main/stdlib/public/core/ContiguousArray.swift#L1318-L1321 [3] https://github.com/apple/swift-collections/blob/main/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary%2BEquatable.swift#L20-L22
Changes
We migrate from:
We migrate to:
Test Plan
Two new tests are added:
OrderedDictionaryValueTests.test_values_getter_equal
OrderedDictionaryValueTests.test_values_getter_not_equal
Checklist