Closed ScottRobbins closed 5 years ago
With my README example (which is a bad example but readily available to start with), the framework with diffing takes ~1.2ms to do the diffing, and about 0.2ms for the layout pass.
Total about 1.4ms
I changed the implementation to just deactivate all of the old constraints and activate the new ones
Without the layout pass included, the updateConstraints method now takes ~1.8ms The layout pass itself takes ~0.2ms
total, about 2ms
This, however, still has all of the constraints wrapped, so maybe the not-diffing part will be faster if i don't do that
It's not really any different when removing the constraint wrapping. the NSLayoutconstraint.activate
method must be the biggest bottleneck here that the larger number of constraints it has to deal with takes longer than doing the diffing and updating properties on constraints already there.
Which is interesting, I thought the bottleneck would be during the layout pass, but really it's whatever work autolayout has to do when you activate/deactivate constraints.
aaand I've been benchmarking on a Debug build 🤦♂️
Well after running in release, it doesn't help the removing all constraints and re-adding all very much. That time stays pretty consistent. Though the total time for the implemented constraint diffing drops the diffing time to ~0.75ms, so a total of 1ms.
For this scenario, doing the constraint diffing seems to be about 100% faster
Increasing this now to 100 views instead of what's just in the READMe.
Total time current implementation: 1.7, 1.8ms, something like that Total time for removing all constraints and re-adding: similar, 1.6, 1.7ms.
So they kind of evened out
Let's do it for 20 views (and so 20 constraints), much more like reality Current: 1ms Removing all/re-adding: 1.6ms
It seems that the constraint diffing performs significantly better for normal usage. As your constraint number increases the time to diff them will eventually be surpassed by deactivating/activating constraints it seems.
I'm not trying to solve for outliers, so this doesn't really bother me. However, there's definitely room for improvement with the constraint diffing
I know apple recommends not removing all constraints, which I agree with. So I want to make sure that the amount of time the framework takes to do diffing is less than the amount of time to do another layout pass as a sanity check