By any chance did you have any more details you might be able to share publicly about how these changes to Observable affected SwiftUI performance? Are there any publicly available benchmarks or measurements we made to quantify how these changes improve SwiftUI performance? What would be our test group? What would be our control group? Is there one specific sample application project you can share that is a good place for us to measure performance with these changes?
This pitch:
Gives us an additional hook to try and optimize the performance of Observable. This change would enable us to migrate something like this:
private nonisolated func shouldNotifyObservers<T>(_ lhs: T, _ rhs: T) -> Bool {
true
}
private nonisolated func shouldNotifyObservers<T: Equatable>(_ lhs: T, _ rhs: T) -> Bool {
lhs != rhs
}
private nonisolated func shouldNotifyObservers<T: AnyObject>(_ lhs: T, _ rhs: T) -> Bool {
lhs !== rhs
}
private nonisolated func shouldNotifyObservers<T: Equatable & AnyObject>(_ lhs: T, _ rhs: T) -> Bool {
lhs != rhs
}
To something like this:
private nonisolated func shouldNotifyObservers<T>(_ lhs: T, _ rhs: T) -> Bool {
true
}
private nonisolated func shouldNotifyObservers<T: Equatable>(_ lhs: T, _ rhs: T) -> Bool {
if let isKnownIdentical = lhs.isKnownIdentical(to: rhs) {
return isKnownIdentical
}
return lhs != rhs
}
private nonisolated func shouldNotifyObservers<T: AnyObject>(_ lhs: T, _ rhs: T) -> Bool {
lhs !== rhs
}
private nonisolated func shouldNotifyObservers<T: Equatable & AnyObject>(_ lhs: T, _ rhs: T) -> Bool {
if let isKnownIdentical = lhs.isKnownIdentical(to: rhs) {
return isKnownIdentical
}
return lhs != rhs
}
Instead of blocking our observation notification on a check for value equality… we now have the option to "fast-path" and check for identity equality. We can also fall back to the 6.2 behavior and check value equality if the type we are observing does not have any concept of equality by identity: like an Int or a Bool.
Before we put this proposal through evolution it might be helpful for the LSG if we had some "real world" impact we can show to demonstrate why this proposal should ship on Equatable. If we could point back to SwiftUI performance improvements… that would be very impactful. If we could then also point back to the same suite of benchmarks and measurements that we referenced before shipping shouldNotifyObservers with value equality that would be even more impactful.