maui
maui copied to clipboard
[iOS] Improve background layer frame mapping performance
Important
This PR Obsoletes a couple of methods.
static Microsoft.Maui.Controls.Platform.BrushExtensions.UpdateBackgroundLayer(this UIKit.UIView view) -> void
static Microsoft.Maui.Platform.ViewExtensions.UpdateBackgroundLayerFrame(this UIKit.UIView! view) -> void
Description of Change
Using https://github.com/davidortinau/AllTheLists app, and scrolling through collection view with Border inside we can clearly see that a good amount of time is spent in UpdateBackgroundLayerFrame which is needed to sync the sublayer with the UIView.Layer.
This has an impact on both MappingFrame and ContentView.LayoutSubviews:
Which translated to these timings
This PR gets rid of all mapping frame code and simply adds an observer on the sublayer.
As a result we get a lot of improvement (80%):
While the new observer is super fast
Issues Fixed
Fixes #24847
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Failing tests definitely unrelated :)
I think this will need to retarget net9.0 , right @PureWeen ?
It doesn't really matter at this point since we aren't releasing anymore SRs from main
To make our lives easier though :-) targeting net9.0 is helpful so we don't have to deal with any surprises once we merge up
I'll take the time to install .NET9 preview and retarget this one on top of that branch.
@rmarinho @PureWeen I've rebased this onto net9.0 branch and retargeted the PR.
May you run /AZP again? thanks
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Hold on on this one, I have to verify something.
So I've come across random crashes in DeviceTests in base.RemoveFromSuperview() invocation and I found out that the problem was strangely caused by the observer.
After an in depth investigation I think I've found the root cause of the problem which I strongly believe lies in Action<NSObservedChange> cback; not being a weak reference too.
This brought me to implement a low-level solution which is now safe (I can't reproduce the crash anymore). https://github.com/dotnet/maui/pull/24848/commits/d8763bfb933a10ea8ba40cb3f872d8068e7b5e62
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
I've added a device test to address memory leak / crash concerns.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Failed test is unrelated.
I've included @Tamilarasan-Paranthaman UI test from https://github.com/dotnet/maui/pull/26222
Azure Pipelines successfully started running 3 pipeline(s).
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
- failing test on iOS/Catalyst is a known issue on main and not related to this PR