Skip to content

Conversation

@albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Nov 4, 2024

Description of Change

This PR includes #25465 and improves it more in order to have iOS CV1 and CV2 handlers rely on native invalidation mechanism rather than subscribing to MeasureInvalidated.

This allows us disable MeasureInvalidated propagation (except for Compatibility.Layout chains).
I've included an app switch to optionally disable the propagation for customers not relying on this event anymore.

/// <summary>
/// A flag that determines whether the measure invalidated event should not be propagated up the visual tree.
/// </summary>
internal static bool SkipMeasureInvalidatedPropagation { get; set /* for testing purpose */; } =
	AppContext.TryGetSwitch("Microsoft.Maui.RuntimeFeature.SkipMeasureInvalidatedPropagation", out var enabled) && enabled;

What's included

  • Provides an app switch to disable MeasureInvalidated propagation (basically "revert"s Make MeasureInvalidated event work correctly #23052 and goes back to 8.0.82) behavior
  • Removal of Compatibility.Layout useless and harming code (causing additional unneeded invalidations)
  • Changed the SetNeedsLayout mechanism which now relies on a more-measurable while-loop
    • The loop stops on UIScrollViews
    • Introduced IMauiPlatformView interface on iOS with two methods
      • InvalidateAncestorsMeasuresWhenMovedToWindow() to schedule propagating invalidation when view is attached to Window
      • InvalidateMeasure(bool isPropagating) to normally simply call SetNeedsLayout on the view
        • Thanks to this interface, we can customize the behavior
  • Refactored iOS CollectionViewHandler1 to use the new platform-level invalidation mechanism
  • Refactored iOS CollectionViewHandler2 to use the new platform-level invalidation mechanism
    • Before this change, CV2 was not reacting to measure changes from items

Using #25671 UI test I've been able to measure the benefits of this PR over main branch.
Please note no-resize on CV2 main (as item size detection was not implemented).

Branch Handler Measure Arrange
main CV1 525 308
PR CV1 252 228
main CV2 (no-resize) 1371 347
PR CV2 464 347

As we can see, CV1 is doing better than CV2 but anyway both look blazing fast compared to main where hiccups are very noticeable with this app!

Also note that the faster you scroll, the higher improvements we can get compared to main.

Issues Fixed

Fixes #25650
Fixes #24996
Fixes #25391
Fixes #25264

Videos of AllTheLists

Captured using a modified version of https://github.com/davidortinau/AllTheLists.git compiled in Release mode with a constant number of lessons generated (high number).

challenging.patch

Using CV1

PR-25664-CV1-AllTheLists.mp4

Using CV2

PR-25664-CV2-AllTheLists.mp4

@albyrock87 albyrock87 requested a review from a team as a code owner November 4, 2024 11:49
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Nov 4, 2024
@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch 3 times, most recently from a465e64 to 5bef429 Compare November 4, 2024 14:27
@PureWeen
Copy link
Member

PureWeen commented Nov 4, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch 3 times, most recently from 917a208 to 15d5364 Compare November 5, 2024 12:23
@albyrock87 albyrock87 changed the title Remove MeasureInvalidated bubble-up mechanism and clean-up legacy layouts. Remove MeasureInvalidated bubble-up mechanism / clean-up legacy layouts / fix iOS CV items resize Nov 5, 2024
}
if (trigger == InvalidationTrigger.HorizontalOptionsChanged || trigger == InvalidationTrigger.VerticalOptionsChanged)
{
ComputeConstraintForView(view);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved to VisualElement.InvalidateMeasureInternal()

@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch from 15d5364 to 46b0c6a Compare November 5, 2024 13:18
@rmarinho
Copy link
Member

rmarinho commented Nov 5, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch from 46b0c6a to 4b243d5 Compare November 6, 2024 09:50
@albyrock87 albyrock87 changed the title Remove MeasureInvalidated bubble-up mechanism / clean-up legacy layouts / fix iOS CV items resize Disable MeasureInvalidated propagation by default / clean-up legacy layouts / fix iOS CV items resize Nov 6, 2024
@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch 2 times, most recently from 23499a5 to a53a1e6 Compare November 6, 2024 11:56
@dotnet dotnet deleted a comment from azure-pipelines bot Nov 6, 2024
@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch from a53a1e6 to 4b38afa Compare November 7, 2024 10:08
@dotnet dotnet deleted a comment from azure-pipelines bot Nov 8, 2024
@albyrock87
Copy link
Contributor Author

Yes, regarding your issue the fix is the same, I've just improved the solution to also fix other issues.
Thanks for confirming it works!

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch from 17c2504 to ddf5b2d Compare November 13, 2024 07:54
@PureWeen PureWeen added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Nov 18, 2024
@albyrock87 albyrock87 force-pushed the legacy-layout-cleanup branch from 373bb74 to 78781b2 Compare November 19, 2024 11:42
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@FlavioGoncalves-Cayas
Copy link

Nice work, eagerly awaiting this merge. Is there an ETA?

@FlavioGoncalves-Cayas
Copy link

@albyrock87 @PureWeen
We are holding back on a larger release for one of our customers apps because the performance is unbearable in some cases. Can you estimate if this will find it's way into a SR before the end of the year?

@PureWeen
Copy link
Member

@albyrock87 @PureWeen We are holding back on a larger release for one of our customers apps because the performance is unbearable in some cases. Can you estimate if this will find it's way into a SR before the end of the year?

Have you validated this resolves your issue?

@FlavioGoncalves-Cayas
Copy link

@albyrock87 @PureWeen We are holding back on a larger release for one of our customers apps because the performance is unbearable in some cases. Can you estimate if this will find it's way into a SR before the end of the year?

Have you validated this resolves your issue?

To be honest, no. I can't find a build of this PR. Can you point me to one?

@albyrock87
Copy link
Contributor Author

To be honest, no. I can't find a build of this PR. Can you point me to one?

@FlavioGoncalves-Cayas you can download the NuGet packages to a local folder from here:
https://dev.azure.com/xamarin/public/_build/results?buildId=128765&view=artifacts&pathAsName=false&type=publishedArtifacts

Pick the nuget artifact zip, it should contain everything you need.
There's also nuget-macos (but I've never understood the difference from the other one).

If you're still on .NET8 you can try out my custom Android/iOS MAUI build from GitHub feed https://github.com/nalu-development/maui-custom/pkgs/nuget/Microsoft.Maui.Controls which contains this PR and other of my PRs still pending merge.

Anyway I think MAUI team would appreciate you testing the nuget packages from this PR.

@PureWeen PureWeen requested a review from jfversluis as a code owner December 13, 2024 16:22
@PureWeen
Copy link
Member

/azp run

@PureWeen
Copy link
Member

@albyrock87 @PureWeen We are holding back on a larger release for one of our customers apps because the performance is unbearable in some cases. Can you estimate if this will find it's way into a SR before the end of the year?

Have you validated this resolves your issue?

To be honest, no. I can't find a build of this PR. Can you point me to one?

Also, if you have a repro of your performance issues that would be helpful as well

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87
Copy link
Contributor Author

I've been asked to separate this into multiple smaller PRs to reduce time to review and impact evaluation, so I'm moving this to draft to not cause confusion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution platform/ios

Projects

None yet

6 participants