Skip to content

[Windows] Optimize WrapperView#24281

Merged
jfversluis merged 5 commits into
dotnet:mainfrom
MartyIX:feature/2024-08-16-Windows-WrapperView-optimize-FINAL
Aug 20, 2024
Merged

[Windows] Optimize WrapperView#24281
jfversluis merged 5 commits into
dotnet:mainfrom
MartyIX:feature/2024-08-16-Windows-WrapperView-optimize-FINAL

Conversation

@MartyIX

@MartyIX MartyIX commented Aug 16, 2024

Copy link
Copy Markdown
Contributor

Description of Change

This PR attempts to optimize WrapperView class on Windows. Not every WrapperView has a border or a shadow set, so it can be set up when it's really needed.

Performance impact

image

-> 93% improvement for the execution of the constructor.

Issues Fixed

@MartyIX MartyIX requested a review from a team as a code owner August 16, 2024 15:12
@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 16, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

DisposeShadow();
DisposeBorder();

GC.SuppressFinalize(this);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested by MSVS.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jonathanpeppers is this the correct thing to do? Do we trust the AI?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's suggested by a dotnet analyzer FTR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. I think to finish out this pattern we need to add a finalizer as well https://learn.microsoft.com/en-us/dotnet/api/system.idisposable?view=net-8.0#examples

  2. I'm not really a fan of this implementing IDisposable at all, but I don't think we can really do anything about that now

@MartyIX MartyIX Aug 18, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed that change in be1ecb2 to avoid increasing scope of this PR.

Comment thread src/Core/src/Platform/Windows/WrapperView.cs
Comment on lines +131 to +135
if (_borderPath is null)
{
_borderPath = new();
Children.Add(_borderPath);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If not initialized, initialize now. A part of the main change.

Comment on lines +219 to +223
if (_shadowCanvas is null)
{
_shadowCanvas = new();
Children.Add(_shadowCanvas);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A part of the main change.

{
public partial class WrapperView : Grid, IDisposable
{
readonly Canvas _shadowCanvas;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: It was readonly but then _shadowCanvas was checked if it is null or not.

Foda
Foda previously approved these changes Aug 16, 2024
@PureWeen

PureWeen commented Aug 16, 2024

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis

Copy link
Copy Markdown
Member

A bunch of tests failed, I retried them now but if they still fail that might be something to look into

@MartyIX

MartyIX commented Aug 18, 2024

Copy link
Copy Markdown
Contributor Author

A bunch of tests failed, I retried them now but if they still fail that might be something to look into

Yes, the PR changes the behavior, it can be seen with Microsoft.Maui.TestCases.Tests.Issues.Issue16094(Windows).ShadowsDontRespectControlShape test:

MAIN PR
image image

Working on fixing that.

@MartyIX

MartyIX commented Aug 18, 2024

Copy link
Copy Markdown
Contributor Author

With 65ddf79 and 674ec0d, I can see ShadowsDontRespectControlShape and WhenTapButtonThenListViewsChangesVisibility tests to pass.

Edit: Thanks @PureWeen for the idea.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis requested review from Foda and PureWeen August 19, 2024 12:19
@jfversluis jfversluis enabled auto-merge (squash) August 19, 2024 12:19
@jfversluis jfversluis merged commit 639fcb0 into dotnet:main Aug 20, 2024
@samhouts samhouts added fixed-in-net9.0-nightly This may be available in a nightly release! fixed-in-net8.0-nightly This may be available in a nightly release! labels Aug 27, 2024
@MartyIX MartyIX deleted the feature/2024-08-16-Windows-WrapperView-optimize-FINAL branch September 10, 2024 18:38
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution fixed-in-net8.0-nightly This may be available in a nightly release! fixed-in-net9.0-nightly This may be available in a nightly release!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants