Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip useless handler mappings calls while connecting #27259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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 (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

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

/azp run

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.

/// <summary>
/// Maps the abstract <see cref="IBorderStroke.Shape"/> property to the platform-specific implementations.
/// </summary>
/// <param name="handler">The associated handler.</param>
/// <param name="border">The associated <see cref="IBorderView"/> instance.</param>
public static void MapStrokeShape(IBorderHandler handler, IBorderView border)
{
if (ShouldSkipStrokeMappings(handler)) return;
Copy link
Contributor

@MartyIX MartyIX Jan 24, 2025

Choose a reason for hiding this comment

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

Nit but this makes putting breakpoints easier:

Suggested change
if (ShouldSkipStrokeMappings(handler)) return;
if (ShouldSkipStrokeMappings(handler))
{
return;
}

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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