nalexn / anyview-vs-group

Benchmarking the performance of AnyView and ConditionalView (Group)
MIT License
13 stars 1 forks source link

Did `==` fire? #1

Open gilbox opened 4 years ago

gilbox commented 4 years ago

Thanks for putting this together, it's so useful to see some benchmarks and not just speculation.

I was wondering if you confirmed that the == function fired for your Equatable View? I've noticed that for simple Views SwiftUI often won't ever call ==.

nalexn commented 4 years ago

The current implementation of EquatableView in SwiftUI actually behaves in a weird way.

The == function is fired not for every act of diffing, as we all would expect, but under very strange circumstances.

I could find two scenarios: after interface orientation change, and at random times under profiling.

So, the test for EquatableView performed much better even without factual use of == function, just the act of wrapping the view in EquatableView already improves performance.

Currently, SwiftUI internals are not optimized for achieving the expected effects: EquatableView being more performant than typed hierarchy and even more performant compared to type-erased hierarchy with AnyView.