KEMBAR78
Skip useless handler mappings calls while connecting by albyrock87 · Pull Request #27259 · dotnet/maui · GitHub
Skip to content

Conversation

@albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Jan 21, 2025

Description of Change

This is an alternative initial version of #27042.
Everything has already been explained there.

Based on/includes #28077 PR

Credits to @MartyIX to have explored the effectiveness of skipping specific mappers.

Key differences from the other PR:

  • Avoid pre-mapping defaults: if the developer replaced the mapper and we skip execution, we're also skipping their custom code which would bring them wonder why their code it's not working while it should be
  • Adds easy-to-use extension methods to IElement and IElementHandler to get the handler state
  • We can selectively skip native calls close to them and by platform (for example on iOS MappingFrame takes care of all the coordinates, even translations, while on other platforms the situation is different)

Benchmark using Nalu Weather app

https://github.com/nalu-development/nalu/tree/main/Samples/Nalu.Maui.Weather

Click on the links in the table to download the speedscope.json file.

Platform SetVirtualView (SR4) SetVirtualView (PR) Improvement
iOS 411.99ms 233.62ms 43%
Android 340.62ms 299.34ms 12%
Windows 1.94s 1.50s 22%

Thanks to @MartyIX for collecting speedscopes on Windows!

Benchmark (from CI - on iOS UI tests)

Note: there is some variability in the benchmark caused by the runner itself, but looking at many recent PRs, main branch never goes under 2600ms.

main branch

image

#27042 original PR

image

this PR
image

Issues Fixed

Fixes #17303

@albyrock87 albyrock87 requested a review from a team as a code owner January 21, 2025 17:43
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 21, 2025
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87 albyrock87 force-pushed the skip-useless-initial-handler-mappings-calls branch from 5573017 to 893e551 Compare January 22, 2025 20:29
@PureWeen
Copy link
Member

PureWeen commented Jan 23, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Comment on lines +13 to +14
internal static bool IsMappingProperties(this IElementHandler handler) =>
(handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.MappingProperties) ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

The method as-is is user-friendly. However, the result is perhaps unexpected when handler is not IElementHandlerStateExhibitor. In that case, I would expect to get null (and not false) as it would tell me "perhaps the handler is actually mapping properties but it does not provide the information". Though, I'm aware that that might lead to less friendly API.

Anyway, feel free to ignore if you feel like it does not add any value.

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 is only temporary for .NET9, and the ?. is there for type safety.
Hopefully these methods will be public and moved to IElementHandler in .NET10.

@bcaceiro
Copy link

Is this already available in nightlies?

@marcojak
Copy link

Definitely it would be good to try it.

Great to see attention to the performances as MAUI struggles a lot there.

@albyrock87
Copy link
Contributor Author

Is this already available in nightlies?

Try this out and let us know: 9.0.40-ci.main.25073.66

@bcaceiro
Copy link

@albyrock87 just tried the latest nightly, everything seems smooth! ( only tested so far on Android)

@PureWeen
Copy link
Member

@albyrock87 just tried the latest nightly, everything seems smooth! ( only tested so far on Android)

do you have a repro I can test against to compare before and after this PR?

Or possibly a video of what you mean by "everything seems smooth"?

@bcaceiro
Copy link

@PureWeen not really, since my app is quite complex (ble, views, etc) I haven't still recorded a speedscope, so it is really just more a "feeling" than any measurable data. In debug mode, and release mode, it seems the loads are a bit faster in pages Appearing, not dramatically faster, but seems faster.

Once I have opportunity I will try to record something though

@albyrock87
Copy link
Contributor Author

@bcaceiro if you record the speedscopes for comparison, you should check timings on SetVirtualView method.

@bcaceiro
Copy link

bcaceiro commented Feb 4, 2025

Update: this is not available on nightlies. So I really didn' test this PR in my previous "feeling".
Nevertheless, now I have sucessfully configured manually the downloaded Nuget, and yes, now it is noticeable in a page with a collectionview, labels and 2 buttons, the difference in the render ( in debug mode). I haven't recorded a speedscope since I'm having some issues with VSCode.

@OvrBtn
Copy link

OvrBtn commented Feb 4, 2025

@MartyIX If I remember correctly in case of this page most of the delay is thanks to CollectionView and ContentPresenter but maybe it will be useful somehow
https://github.com/OvrBtn/MAUIPerf/blob/master/MAUIPerf/Views/CollectionView1Page.xaml

If you want I can try to create some example based more around changes in this PR but from what I've seen you already have one.
(Testing on real device (Samsung Galaxy A50, release config)

version image image
video
v30.mp4
v40.mp4

@albyrock87 albyrock87 force-pushed the skip-useless-initial-handler-mappings-calls branch from 893e551 to 21694d0 Compare February 26, 2025 12:13
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR6 milestone Feb 26, 2025
@albyrock87 albyrock87 force-pushed the skip-useless-initial-handler-mappings-calls branch 3 times, most recently from 69a569a to f15369c Compare February 28, 2025 13:48
@github-actions github-actions bot force-pushed the skip-useless-initial-handler-mappings-calls branch from a65cfad to e8ced3c Compare June 25, 2025 20:05
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Test failures on this one seem accurate

image

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Jun 26, 2025
/// <param name="view">The associated <see cref="IView"/> instance.</param>
public static void MapFlowDirection(IViewHandler handler, IView view)
{
if (handler.IsConnectingHandler() && view.FlowDirection == FlowDirection.MatchParent) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is preventing FlowDirection propagation to child view

Since now path wont make it to this

updateValue = GetParentMatchingSemanticContentAttribute(view);

Related failing test : EntryClearButtonWorks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, apparently UIKit is the only one not having an automatic MatchParent behavior, so I'm gonna skip this check if it's IOS || MACCATALYST.

return;
}
#else
if (handler.IsConnectingHandler() && double.IsNaN(view.MinimumWidth)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

@albyrock87 This should not be on Windows to fix the check box test.

@PureWeen
Copy link
Member

/azp run

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Jun 27, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen changed the base branch from main to inflight/current June 27, 2025 18:09
@PureWeen PureWeen merged commit 7cb5ba5 into dotnet:inflight/current Jun 27, 2025
124 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Jun 27, 2025
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Jun 28, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jun 29, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jun 29, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 1, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 2, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 2, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 8, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 8, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jul 9, 2025
* Skip useless initial handler mappings calls

* Apply suggestions from code review, fixes check on Maximum*

* Windows: automation properties are extremely costly

* Fix broken UI tests

* Workaround Windows broken tests

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-core-platform Integration with platforms community ✨ Community Contribution

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[performance] all PropertyMapper's set the same values over and over