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

[android] avoid OnLayout() for Label #21291

Merged

Commits on Mar 26, 2024

  1. [android] avoid OnLayout() for Label

    Context: dotnet#18505
    Context: https://github.com/dotnet/maui/files/13251041/MauiCollectionView.zip
    Context: dotnet#21229 (review)
    
    In profiling scrolling of an app with a `<CollectionView/>` and 12
    `<Label/>`s, we see time spent in:
    
        1.9% Microsoft.Maui!Microsoft.Maui.Platform.MauiTextView.OnLayout(bool,int,int,int,int)
    
    This is a callback from Java to C#, which has a performance cost.
    Reviewing the code, we would only need to make this callback *at all*
    if `Label.FormattedText` is not `null`. The bulk of all `Label`'s can
    avoid this call?
    
    To do this:
    
    * Write a new `PlatformAppCompatTextView.java` that override `onLayout()`
    
    * It only calls `onLayoutFormatted()` if a `isFormatted` `boolean`
      field is `true`
    
    * We can set `isFormatted` if a formatted string is such as:
      `isFormatted = !(text instanceof String)`
    
    With this change in place, the above `MauiTextView.OnLayout()` call is
    completely gone from `dotnet-trace` output. Scrolling the sample also
    "feels" a bit snappier.
    
    This should improve the performance of all non-formatted `Label`s on
    Android.
    
    This is the mininum amount of API changes possible -- which seems like
    what we should go for if we ship this change in .NET 8 servicing.
    jonathanpeppers committed Mar 26, 2024
    Configuration menu
    Copy the full SHA
    c8aebdc View commit details
    Browse the repository at this point in the history