Skip to content

[ios/catalyst] avoid duplicating UIView.Subviews arrays #21765

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

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

jonathanpeppers
Copy link
Member

Context: #21580
Similar to: #21308

Recording this app in dotnet-trace, I saw:

(0.81%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()

Where this time is spent in:

  • Microsoft.Maui!Microsoft.Maui.Platform.WrapperView

Reviewing the code, it calls this.Subviews twice, which would marshal and create two arrays. It then calls Subviews[0].

Storing in a local instead will avoid creating the array twice:

var subviews = Subviews;
if (subviews.Length == 0)
    return;
//...
var child = subviews[0];

This improves things a small amount, but is probably worth it:

(0.72%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()

I'll think about making an analyzer for this, but I didn't find any similar cases that appear in dotnet-trace at the moment.

This doesn't fully solve #21580, but it's a small improvement.

Context: #21580
Similar to: #21308

Recording this app in `dotnet-trace`, I saw:

    (0.81%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()

Where this time is spent in:

* `Microsoft.Maui!Microsoft.Maui.Platform.WrapperView`

Reviewing the code, it calls `this.Subviews` twice, which would marshal
and create two arrays. It then calls `Subviews[0]`.

Storing in a local instead will avoid creating the array twice:

    var subviews = Subviews;
    if (subviews.Length == 0)
        return;
    //...
    var child = subviews[0];

This improves things a small amount, but is probably worth it:

    (0.72%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()

I'll think about making an analyzer for this, but  I didn't find any
similar cases that appear in `dotnet-trace` at the moment.

This doesn't fully solve #21580, but it's a small improvement.
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner April 10, 2024 21:48
@jonathanpeppers jonathanpeppers requested review from jfversluis and PureWeen and removed request for a team April 10, 2024 21:48
@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@rmarinho rmarinho merged commit b898d09 into release/8.0.1xx-sr4 Apr 11, 2024
@rmarinho rmarinho deleted the dev/peppers/Subviews branch April 11, 2024 11:50
@jonathanpeppers
Copy link
Member Author

I just realized when I tested this -- I wasn't using my local build of MAUI!

This might help slightly more than I originally thought:

Before:
(0.81%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()
After:
(0.44%)	Microsoft.MacCatalyst!UIKit.UIView.get_Subviews()

@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants